| 164 | |
| 165 | |
| 166 | static int luaB_close (lua_State *L) { |
| 167 | lua_State *co = getco(L); |
| 168 | int status = auxstatus(L, co); |
| 169 | switch (status) { |
| 170 | case COS_DEAD: case COS_YIELD: { |
| 171 | status = lua_resetthread(co); |
| 172 | if (status == LUA_OK) { |
| 173 | lua_pushboolean(L, 1); |
| 174 | return 1; |
| 175 | } |
| 176 | else { |
| 177 | lua_pushboolean(L, 0); |
| 178 | lua_xmove(co, L, 1); /* copy error message */ |
| 179 | return 2; |
| 180 | } |
| 181 | } |
| 182 | default: /* normal or running coroutine */ |
| 183 | return luaL_error(L, "cannot close a %s coroutine", statname[status]); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | |
| 188 | static const luaL_Reg co_funcs[] = { |
nothing calls this directly
no test coverage detected