aboutsummaryrefslogtreecommitdiff
path: root/src/lua/lstate.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/lstate.c')
-rw-r--r--src/lua/lstate.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/lua/lstate.c b/src/lua/lstate.c
index 1596b51..92ccbf9 100644
--- a/src/lua/lstate.c
+++ b/src/lua/lstate.c
@@ -268,7 +268,7 @@ static void preinit_thread (lua_State *L, global_State *g) {
268 268
269static void close_state (lua_State *L) { 269static void close_state (lua_State *L) {
270 global_State *g = G(L); 270 global_State *g = G(L);
271 luaF_close(L, L->stack, CLOSEPROTECT); /* close all upvalues */ 271 luaD_closeprotected(L, 0, LUA_OK); /* close all upvalues */
272 luaC_freeallobjects(L); /* collect all objects */ 272 luaC_freeallobjects(L); /* collect all objects */
273 if (ttisnil(&g->nilvalue)) /* closing a fully built state? */ 273 if (ttisnil(&g->nilvalue)) /* closing a fully built state? */
274 luai_userstateclose(L); 274 luai_userstateclose(L);
@@ -313,7 +313,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
313 313
314void luaE_freethread (lua_State *L, lua_State *L1) { 314void luaE_freethread (lua_State *L, lua_State *L1) {
315 LX *l = fromstate(L1); 315 LX *l = fromstate(L1);
316 luaF_close(L1, L1->stack, NOCLOSINGMETH); /* close all upvalues */ 316 luaF_close(L1, L1->stack, NOCLOSINGMETH, 0); /* close all upvalues */
317 lua_assert(L1->openupval == NULL); 317 lua_assert(L1->openupval == NULL);
318 luai_userstatefree(L, L1); 318 luai_userstatefree(L, L1);
319 freestack(L1); 319 freestack(L1);
@@ -321,23 +321,29 @@ void luaE_freethread (lua_State *L, lua_State *L1) {
321} 321}
322 322
323 323
324int lua_resetthread (lua_State *L) { 324int luaE_resetthread (lua_State *L, int status) {
325 CallInfo *ci; 325 CallInfo *ci = L->ci = &L->base_ci; /* unwind CallInfo list */
326 int status;
327 lua_lock(L);
328 L->ci = ci = &L->base_ci; /* unwind CallInfo list */
329 setnilvalue(s2v(L->stack)); /* 'function' entry for basic 'ci' */ 326 setnilvalue(s2v(L->stack)); /* 'function' entry for basic 'ci' */
330 ci->func = L->stack; 327 ci->func = L->stack;
331 ci->callstatus = CIST_C; 328 ci->callstatus = CIST_C;
332 status = luaF_close(L, L->stack, CLOSEPROTECT); 329 if (status == LUA_YIELD)
333 if (status != CLOSEPROTECT) /* real errors? */
334 luaD_seterrorobj(L, status, L->stack + 1);
335 else {
336 status = LUA_OK; 330 status = LUA_OK;
331 status = luaD_closeprotected(L, 0, status);
332 if (status != LUA_OK) /* errors? */
333 luaD_seterrorobj(L, status, L->stack + 1);
334 else
337 L->top = L->stack + 1; 335 L->top = L->stack + 1;
338 }
339 ci->top = L->top + LUA_MINSTACK; 336 ci->top = L->top + LUA_MINSTACK;
340 L->status = status; 337 L->status = cast_byte(status);
338 luaD_reallocstack(L, cast_int(ci->top - L->stack), 0);
339 return status;
340}
341
342
343LUA_API int lua_resetthread (lua_State *L) {
344 int status;
345 lua_lock(L);
346 status = luaE_resetthread(L, L->status);
341 lua_unlock(L); 347 lua_unlock(L);
342 return status; 348 return status;
343} 349}