diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-11-02 09:28:56 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-11-02 09:28:56 -0200 |
| commit | ba36180fd7b68341ad57e0fbe7a55cdfb334908d (patch) | |
| tree | c99f2d1335c90aad7015475e64cecbea889cefcc /ldo.c | |
| parent | b9e76be8a691ed83a716a85c6b85cb80f66cc480 (diff) | |
| download | lua-ba36180fd7b68341ad57e0fbe7a55cdfb334908d.tar.gz lua-ba36180fd7b68341ad57e0fbe7a55cdfb334908d.tar.bz2 lua-ba36180fd7b68341ad57e0fbe7a55cdfb334908d.zip | |
new API for 'lua_resume' + cleaning the uses of the 'extra' field in
'CallInfo'
Diffstat (limited to 'ldo.c')
| -rw-r--r-- | ldo.c | 14 |
1 files changed, 8 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.163 2017/10/31 17:54:35 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.164 2017/11/01 18:20:48 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -559,7 +559,7 @@ static int recover (lua_State *L, int status) { | |||
| 559 | CallInfo *ci = findpcall(L); | 559 | CallInfo *ci = findpcall(L); |
| 560 | if (ci == NULL) return 0; /* no recovery point */ | 560 | if (ci == NULL) return 0; /* no recovery point */ |
| 561 | /* "finish" luaD_pcall */ | 561 | /* "finish" luaD_pcall */ |
| 562 | oldtop = restorestack(L, ci->extra); | 562 | oldtop = restorestack(L, ci->u2.funcidx); |
| 563 | luaF_close(L, oldtop); | 563 | luaF_close(L, oldtop); |
| 564 | seterrorobj(L, status, oldtop); | 564 | seterrorobj(L, status, oldtop); |
| 565 | L->ci = ci; | 565 | L->ci = ci; |
| @@ -604,7 +604,6 @@ static void resume (lua_State *L, void *ud) { | |||
| 604 | else { /* resuming from previous yield */ | 604 | else { /* resuming from previous yield */ |
| 605 | lua_assert(L->status == LUA_YIELD); | 605 | lua_assert(L->status == LUA_YIELD); |
| 606 | L->status = LUA_OK; /* mark that it is running (again) */ | 606 | L->status = LUA_OK; /* mark that it is running (again) */ |
| 607 | L->func = ci->func = restorestack(L, ci->extra); | ||
| 608 | if (isLua(ci)) /* yielded inside a hook? */ | 607 | if (isLua(ci)) /* yielded inside a hook? */ |
| 609 | luaV_execute(L); /* just continue running Lua code */ | 608 | luaV_execute(L); /* just continue running Lua code */ |
| 610 | else { /* 'common' yield */ | 609 | else { /* 'common' yield */ |
| @@ -622,7 +621,8 @@ static void resume (lua_State *L, void *ud) { | |||
| 622 | } | 621 | } |
| 623 | 622 | ||
| 624 | 623 | ||
| 625 | LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) { | 624 | LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs, |
| 625 | int *nresults) { | ||
| 626 | int status; | 626 | int status; |
| 627 | unsigned short oldnny = L->nny; /* save "number of non-yieldable" calls */ | 627 | unsigned short oldnny = L->nny; /* save "number of non-yieldable" calls */ |
| 628 | lua_lock(L); | 628 | lua_lock(L); |
| @@ -653,6 +653,8 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs) { | |||
| 653 | } | 653 | } |
| 654 | else lua_assert(status == L->status); /* normal end or yield */ | 654 | else lua_assert(status == L->status); /* normal end or yield */ |
| 655 | } | 655 | } |
| 656 | *nresults = (status == LUA_YIELD) ? L->ci->u2.nyield | ||
| 657 | : L->top - (L->func + 1); | ||
| 656 | L->nny = oldnny; /* restore 'nny' */ | 658 | L->nny = oldnny; /* restore 'nny' */ |
| 657 | L->nCcalls--; | 659 | L->nCcalls--; |
| 658 | lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0)); | 660 | lua_assert(L->nCcalls == ((from) ? from->nCcalls : 0)); |
| @@ -679,14 +681,14 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, | |||
| 679 | luaG_runerror(L, "attempt to yield from outside a coroutine"); | 681 | luaG_runerror(L, "attempt to yield from outside a coroutine"); |
| 680 | } | 682 | } |
| 681 | L->status = LUA_YIELD; | 683 | L->status = LUA_YIELD; |
| 682 | ci->extra = savestack(L, L->func); /* save current 'func' */ | ||
| 683 | if (isLua(ci)) { /* inside a hook? */ | 684 | if (isLua(ci)) { /* inside a hook? */ |
| 684 | api_check(L, k == NULL, "hooks cannot continue after yielding"); | 685 | api_check(L, k == NULL, "hooks cannot continue after yielding"); |
| 686 | ci->u2.nyield = 0; /* no results */ | ||
| 685 | } | 687 | } |
| 686 | else { | 688 | else { |
| 687 | if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ | 689 | if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ |
| 688 | ci->u.c.ctx = ctx; /* save context */ | 690 | ci->u.c.ctx = ctx; /* save context */ |
| 689 | L->func = ci->func = L->top - nresults - 1; /* protect stack below results */ | 691 | ci->u2.nyield = nresults; /* save number of results */ |
| 690 | luaD_throw(L, LUA_YIELD); | 692 | luaD_throw(L, LUA_YIELD); |
| 691 | } | 693 | } |
| 692 | lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */ | 694 | lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */ |
