diff options
Diffstat (limited to 'lstate.c')
| -rw-r--r-- | lstate.c | 27 |
1 files changed, 25 insertions, 2 deletions
| @@ -258,7 +258,7 @@ static void preinit_thread (lua_State *L, global_State *g) { | |||
| 258 | 258 | ||
| 259 | static void close_state (lua_State *L) { | 259 | static void close_state (lua_State *L) { |
| 260 | global_State *g = G(L); | 260 | global_State *g = G(L); |
| 261 | luaF_close(L, L->stack, -1); /* close all upvalues for this thread */ | 261 | luaF_close(L, L->stack, CLOSEPROTECT); /* close all upvalues */ |
| 262 | luaC_freeallobjects(L); /* collect all objects */ | 262 | luaC_freeallobjects(L); /* collect all objects */ |
| 263 | if (ttisnil(&g->nilvalue)) /* closing a fully built state? */ | 263 | if (ttisnil(&g->nilvalue)) /* closing a fully built state? */ |
| 264 | luai_userstateclose(L); | 264 | luai_userstateclose(L); |
| @@ -301,7 +301,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) { | |||
| 301 | 301 | ||
| 302 | void luaE_freethread (lua_State *L, lua_State *L1) { | 302 | void luaE_freethread (lua_State *L, lua_State *L1) { |
| 303 | LX *l = fromstate(L1); | 303 | LX *l = fromstate(L1); |
| 304 | luaF_close(L1, L1->stack, -1); /* close all upvalues for this thread */ | 304 | luaF_close(L1, L1->stack, NOCLOSINGMETH); /* close all upvalues */ |
| 305 | lua_assert(L1->openupval == NULL); | 305 | lua_assert(L1->openupval == NULL); |
| 306 | luai_userstatefree(L, L1); | 306 | luai_userstatefree(L, L1); |
| 307 | freestack(L1); | 307 | freestack(L1); |
| @@ -309,6 +309,29 @@ void luaE_freethread (lua_State *L, lua_State *L1) { | |||
| 309 | } | 309 | } |
| 310 | 310 | ||
| 311 | 311 | ||
| 312 | int lua_resetthread (lua_State *L) { | ||
| 313 | CallInfo *ci; | ||
| 314 | int status; | ||
| 315 | lua_lock(L); | ||
| 316 | ci = &L->base_ci; | ||
| 317 | status = luaF_close(L, L->stack, CLOSEPROTECT); | ||
| 318 | setnilvalue(s2v(L->stack)); /* 'function' entry for basic 'ci' */ | ||
| 319 | if (status != CLOSEPROTECT) /* real errors? */ | ||
| 320 | luaD_seterrorobj(L, status, L->stack + 1); | ||
| 321 | else { | ||
| 322 | status = LUA_OK; | ||
| 323 | L->top = L->stack + 1; | ||
| 324 | } | ||
| 325 | ci->callstatus = CIST_C; | ||
| 326 | ci->func = L->stack; | ||
| 327 | ci->top = L->top + LUA_MINSTACK; | ||
| 328 | L->ci = ci; | ||
| 329 | L->status = status; | ||
| 330 | lua_unlock(L); | ||
| 331 | return status; | ||
| 332 | } | ||
| 333 | |||
| 334 | |||
| 312 | LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { | 335 | LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { |
| 313 | int i; | 336 | int i; |
| 314 | lua_State *L; | 337 | lua_State *L; |
