Skip to main content

reset_thread

Function reset_thread 

Source
pub fn reset_thread(state: &mut LuaState, status: i32) -> i32
Expand 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).

C: int luaE_resetthread(lua_State *L, int status) — LUAI_FUNC (pub(crate))

// C: int luaE_resetthread(lua_State *L, int status) {
//   CallInfo *ci = L->ci = &L->base_ci;
//   setnilvalue(s2v(L->stack.p));
//   ci->func.p = L->stack.p;
//   ci->callstatus = CIST_C;
//   if (status == LUA_YIELD) status = LUA_OK;
//   L->status = LUA_OK;  /* so it can run __close metamethods */
//   status = luaD_closeprotected(L, 1, status);
//   if (status != LUA_OK) luaD_seterrorobj(L, status, L->stack.p + 1);
//   else L->top.p = L->stack.p + 1;
//   ci->top.p = L->top.p + LUA_MINSTACK;
//   luaD_reallocstack(L, cast_int(ci->top.p - L->stack.p), 0);
//   return status;
// }