diff options
Diffstat (limited to 'lib/lua/src/ldo.c')
-rw-r--r-- | lib/lua/src/ldo.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/lib/lua/src/ldo.c b/lib/lua/src/ldo.c index aa4cf70..f1472b2 100644 --- a/lib/lua/src/ldo.c +++ b/lib/lua/src/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 1.5 2004-11-27 21:46:07 pixel Exp $ +** $Id: ldo.c,v 1.6 2004-12-27 19:52:23 pixel Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -322,11 +322,11 @@ static void resume (lua_State *L, void *ud) { int nargs = *cast(int *, ud); CallInfo *ci = L->ci; if (ci == L->base_ci) { /* no activation record? */ - if (nargs >= L->top - L->base) - luaG_runerror(L, "cannot resume dead coroutine"); + lua_assert(nargs < L->top - L->base); luaD_precall(L, L->top - (nargs + 1)); /* start coroutine */ } - else if (ci->state & CI_YIELD) { /* inside a yield? */ + else { /* inside a yield */ + lua_assert(ci->state & CI_YIELD); if (ci->state & CI_C) { /* `common' yield? */ /* finish interrupted execution of `OP_CALL' */ int nresults; @@ -341,18 +341,31 @@ static void resume (lua_State *L, void *ud) { ci->state &= ~CI_YIELD; } } - else - luaG_runerror(L, "cannot resume non-suspended coroutine"); firstResult = luaV_execute(L); if (firstResult != NULL) /* return? */ luaD_poscall(L, LUA_MULTRET, firstResult); /* finalize this coroutine */ } +static int resume_error (lua_State *L, const char *msg) { + L->top = L->ci->base; + setsvalue2s(L->top, lusS_new(L, msg)); + incr_top(L); + lua_unlock(L); + return LUA_ERRRUN; +} + + LUA_API int lua_resume (lua_State *L, int nargs) { int status; lu_byte old_allowhooks; lua_lock(L); + if (L->ci == L->base_ci) { + if (nargs >= L->top - L->base) + return resume_error(L, "cannot resume dead coroutine"); + } + else if (!(L->ci->state & CI_YIELD)) /* not inside a yield? */ + return resume_error(L, "cannot resume non-suspended coroutine"); old_allowhooks = L->allowhook; lua_assert(L->errfunc == 0 && L->nCcalls == 0); status = luaD_rawrunprotected(L, resume, &nargs); |