diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-26 06:45:36 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-26 06:45:36 -0200 |
commit | 8954bdc7060ec9e977e1a3bb085eca487fd4821d (patch) | |
tree | 311756d7f1782d594e5fc1c8b15dbdc8d28f402a | |
parent | 5a228bb1d8585022dbcd569259c6a9efcd0ddd3c (diff) | |
download | lua-8954bdc7060ec9e977e1a3bb085eca487fd4821d.tar.gz lua-8954bdc7060ec9e977e1a3bb085eca487fd4821d.tar.bz2 lua-8954bdc7060ec9e977e1a3bb085eca487fd4821d.zip |
new `coroutine.status' function
-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 | ||