A coroutine can close itself

A call to close itself will close all its to-be-closed variables and
return to the resume that (re)started the coroutine.
This commit is contained in:
Roberto Ierusalimschy
2025-06-12 11:15:09 -03:00
parent d05fe48bfd
commit fd897027f1
6 changed files with 103 additions and 21 deletions

View File

@@ -326,6 +326,8 @@ LUA_API int lua_closethread (lua_State *L, lua_State *from) {
lua_lock(L);
L->nCcalls = (from) ? getCcalls(from) : 0;
status = luaE_resetthread(L, L->status);
if (L == from) /* closing itself? */
luaD_throwbaselevel(L, status);
lua_unlock(L);
return APIstatus(status);
}