pub fn reset_thread(state: &mut LuaState, status: i32) -> i32Expand description
Reset a thread to its base state, closing all to-be-closed variables.
Returns the final status code as an i32 (mirrors the C API).
Mirrors C’s luaE_resetthread (reference/lua-5.4.7/src/lstate.c) line
for line, including its final luaD_reallocstack(L, ci->top.p - L->stack.p, 0) call — routed here through crate::do_::realloc_stack
with raise_error = false, matching C’s raiseerror = 0. That routes
through the OOM/emergency-GC-stop path (the point of issue #275 item 4)
and updates stack_last, which the old raw Vec::resize left stale.
realloc_stack shrinks the logical stack length back down but, because
it goes through Vec::resize_with, leaves the backing allocation’s
capacity at the high-water mark — a deliberate high-water policy that is
correct for the hot grow/shrink paths but means memory a coroutine grew
deep for is not returned. C’s luaM_reallocvector reallocates to exactly
the new size, releasing that memory, so this cold reset path follows the
realloc with an explicit shrink_to_fit to reclaim the capacity too.
(reset_thread runs on coroutine close/reset, never in a hot loop, so
the extra realloc is not a concern.)