diff options
| -rw-r--r-- | lbaselib.c | 19 |
1 files changed, 18 insertions, 1 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.109 2002/11/22 18:01:46 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.110 2002/11/25 17:33:33 roberto Exp roberto $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -587,11 +587,28 @@ static int luaB_yield (lua_State *L) { | |||
| 587 | return lua_yield(L, lua_gettop(L)); | 587 | return lua_yield(L, lua_gettop(L)); |
| 588 | } | 588 | } |
| 589 | 589 | ||
| 590 | |||
| 591 | static int luaB_costatus (lua_State *L) { | ||
| 592 | lua_State *co = lua_tothread(L, 1); | ||
| 593 | luaL_argcheck(L, co, 1, "coroutine expected"); | ||
| 594 | if (L == co) lua_pushliteral(L, "running"); | ||
| 595 | else { | ||
| 596 | lua_Debug ar; | ||
| 597 | if (lua_getstack(co, 0, &ar) == 0 && lua_gettop(co) == 0) | ||
| 598 | lua_pushliteral(L, "dead"); | ||
| 599 | else | ||
| 600 | lua_pushliteral(L, "suspended"); | ||
| 601 | } | ||
| 602 | return 1; | ||
| 603 | } | ||
| 604 | |||
| 605 | |||
| 590 | static const luaL_reg co_funcs[] = { | 606 | static const luaL_reg co_funcs[] = { |
| 591 | {"create", luaB_cocreate}, | 607 | {"create", luaB_cocreate}, |
| 592 | {"wrap", luaB_cowrap}, | 608 | {"wrap", luaB_cowrap}, |
| 593 | {"resume", luaB_coresume}, | 609 | {"resume", luaB_coresume}, |
| 594 | {"yield", luaB_yield}, | 610 | {"yield", luaB_yield}, |
| 611 | {"status", luaB_costatus}, | ||
| 595 | {NULL, NULL} | 612 | {NULL, NULL} |
| 596 | }; | 613 | }; |
| 597 | 614 | ||
