Jure Bagić
unread,Nov 28, 2025, 1:53:35 PMNov 28Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to lua-l
In lcorolib.c:199 (latest commit 4cf498210e6a60637a7abb06d32460ec21efdbdc)
> default: /* normal or running coroutine */
> return luaL_error(L, "cannot close a %s coroutine", statname[status]);
No need for 'statname[status]' argument, as the COS_RUN status case is already
handled right above the default case.
> case COS_RUN: /* running coroutine? */
> lua_geti(L, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD); /* get main */
> if (lua_tothread(L, -1) == co)
> return luaL_error(L, "cannot close main thread");
> lua_closethread(co, L); /* close itself */
> lua_assert(0); /* previous call does not return */
> return 0;
So just do this:
> default: /* normal coroutine */
> return luaL_error(L, "cannot close a normal coroutine");
Then the 'statname' could be moved into 'luaB_costatus' as this is the
only function that uses it.
> static int luaB_costatus (lua_State *L) {
> static const char *const statname[] =
> {"running", "dead", "suspended", "normal"};
> lua_State *co = getco(L);
> lua_pushstring(L, statname[auxstatus(L, co)]);
> return 1;
> }
--
Jure