Small correction in lcorolib.c

81 views
Skip to first unread message

Jure Bagić

unread,
Nov 28, 2025, 1:53:35 PMNov 28
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
signature.asc

Roberto Ierusalimschy

unread,
Dec 1, 2025, 8:07:46 AMDec 1
to lu...@googlegroups.com
> 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.
> [...]

Thanks for the feedback. This remained from commit fd897027.

-- Roberto
Reply all
Reply to author
Forward
0 new messages