aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-11-26 06:45:36 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-11-26 06:45:36 -0200
commit8954bdc7060ec9e977e1a3bb085eca487fd4821d (patch)
tree311756d7f1782d594e5fc1c8b15dbdc8d28f402a
parent5a228bb1d8585022dbcd569259c6a9efcd0ddd3c (diff)
downloadlua-8954bdc7060ec9e977e1a3bb085eca487fd4821d.tar.gz
lua-8954bdc7060ec9e977e1a3bb085eca487fd4821d.tar.bz2
lua-8954bdc7060ec9e977e1a3bb085eca487fd4821d.zip
new `coroutine.status' function
-rw-r--r--lbaselib.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 76df655e..909a455d 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -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
591static 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
590static const luaL_reg co_funcs[] = { 606static 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