Coroutines do not unwind the stack in case of errors
Back to how it was, a coroutine does not unwind its stack in case of errors (and therefore do not close its to-be-closed variables). This allows the stack to be examined after the error. The program can use 'coroutine.kill' to close the variables. The function created by 'coroutine.wrap', however, closes the coroutine's variables in case of errors, as it is impossible to examine the stack any way.
This commit is contained in:
4
ldo.c
4
ldo.c
@@ -686,10 +686,8 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
|
||||
if (likely(!errorstatus(status)))
|
||||
lua_assert(status == L->status); /* normal end or yield */
|
||||
else { /* unrecoverable error */
|
||||
status = luaF_close(L, L->stack, status); /* close all upvalues */
|
||||
L->status = cast_byte(status); /* mark thread as 'dead' */
|
||||
luaD_seterrorobj(L, status, L->stack + 1); /* push error message */
|
||||
L->ci = &L->base_ci; /* back to the original C level */
|
||||
luaD_seterrorobj(L, status, L->top); /* push error message */
|
||||
L->ci->top = L->top;
|
||||
}
|
||||
*nresults = (status == LUA_YIELD) ? L->ci->u2.nyield
|
||||
|
||||
Reference in New Issue
Block a user