aboutsummaryrefslogtreecommitdiff
path: root/lcorolib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-06-13 14:08:38 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-06-13 14:08:38 -0300
commite657a48ea5698bbd9982d878eb65e6615ec94f7e (patch)
tree2a121476070495f31f9adb201aed7bdb2b48c75a /lcorolib.c
parentfd897027f19288ce2cb0249cb8c1818e2f3f1c4c (diff)
downloadlua-e657a48ea5698bbd9982d878eb65e6615ec94f7e.tar.gz
lua-e657a48ea5698bbd9982d878eb65e6615ec94f7e.tar.bz2
lua-e657a48ea5698bbd9982d878eb65e6615ec94f7e.zip
The main thread cannot be closed
No thread started with pcall (instead of resume) can be closed, because coroutine.close would not respect the expected number of results from the protected call.
Diffstat (limited to 'lcorolib.c')
-rw-r--r--lcorolib.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/lcorolib.c b/lcorolib.c
index 5b9736f1..23dd8441 100644
--- a/lcorolib.c
+++ b/lcorolib.c
@@ -190,6 +190,9 @@ static int luaB_close (lua_State *L) {
190 } 190 }
191 } 191 }
192 case COS_RUN: /* running coroutine? */ 192 case COS_RUN: /* running coroutine? */
193 lua_geti(L, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD); /* get main */
194 if (lua_tothread(L, -1) == co)
195 return luaL_error(L, "cannot close main thread");
193 lua_closethread(co, L); /* close itself */ 196 lua_closethread(co, L); /* close itself */
194 lua_assert(0); /* previous call does not return */ 197 lua_assert(0); /* previous call does not return */
195 return 0; 198 return 0;