| 174 | |
| 175 | |
| 176 | static int luaB_close (lua_State *L) { |
| 177 | lua_State *co = getoptco(L); |
| 178 | int status = auxstatus(L, co); |
| 179 | switch (status) { |
| 180 | case COS_DEAD: case COS_YIELD: { |
| 181 | status = lua_closethread(co, L); |
| 182 | if (status == LUA_OK) { |
| 183 | lua_pushboolean(L, 1); |
| 184 | return 1; |
| 185 | } |
| 186 | else { |
| 187 | lua_pushboolean(L, 0); |
| 188 | lua_xmove(co, L, 1); /* move error message */ |
| 189 | return 2; |
| 190 | } |
| 191 | } |
| 192 | case COS_NORM: |
| 193 | return luaL_error(L, "cannot close a %s coroutine", statname[status]); |
| 194 | case COS_RUN: |
| 195 | lua_geti(L, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD); /* get main */ |
| 196 | if (lua_tothread(L, -1) == co) |
| 197 | return luaL_error(L, "cannot close main thread"); |
| 198 | lua_closethread(co, L); /* close itself */ |
| 199 | /* previous call does not return *//* FALLTHROUGH */ |
| 200 | default: |
| 201 | lua_assert(0); |
| 202 | return 0; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | |
| 207 | static const luaL_Reg co_funcs[] = { |
nothing calls this directly
no test coverage detected