From 409256b7849ec5ab3296cb0ab9eba3d65955d5ea Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 18 Dec 2020 11:22:42 -0300 Subject: 'coroutine.close'/'lua_resetthread' report original errors Besides errors in closing methods, 'coroutine.close' and 'lua_resetthread' also consider the original error that stopped the thread, if any. --- lstate.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lstate.c') diff --git a/lstate.c b/lstate.c index 1596b51c..96187c66 100644 --- a/lstate.c +++ b/lstate.c @@ -323,14 +323,16 @@ void luaE_freethread (lua_State *L, lua_State *L1) { int lua_resetthread (lua_State *L) { CallInfo *ci; - int status; + int status = L->status; lua_lock(L); L->ci = ci = &L->base_ci; /* unwind CallInfo list */ setnilvalue(s2v(L->stack)); /* 'function' entry for basic 'ci' */ ci->func = L->stack; ci->callstatus = CIST_C; - status = luaF_close(L, L->stack, CLOSEPROTECT); - if (status != CLOSEPROTECT) /* real errors? */ + if (status == LUA_OK || status == LUA_YIELD) + status = CLOSEPROTECT; /* run closing methods in protected mode */ + status = luaF_close(L, L->stack, status); + if (status != CLOSEPROTECT) /* errors? */ luaD_seterrorobj(L, status, L->stack + 1); else { status = LUA_OK; -- cgit v1.2.3-55-g6feb