diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-02-09 09:56:29 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-02-09 09:56:29 -0200 |
commit | 4c54cd3a107d1b394d7591f8c3ecd0b79885ff30 (patch) | |
tree | 80856b8c2ad76f26adb31378f8e68ecd78b279fa /ldo.c | |
parent | c8ff7de7f0be3abd4bb80682bda2bafc12503732 (diff) | |
download | lua-4c54cd3a107d1b394d7591f8c3ecd0b79885ff30.tar.gz lua-4c54cd3a107d1b394d7591f8c3ecd0b79885ff30.tar.bz2 lua-4c54cd3a107d1b394d7591f8c3ecd0b79885ff30.zip |
when yielding, original 'func' value must be kept and restored so
that 'poscall' puts results in the right slot.
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.79 2009/12/22 15:32:50 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.80 2010/01/13 16:17:32 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 | */ |
@@ -452,7 +452,7 @@ static int recover (lua_State *L, int status) { | |||
452 | CallInfo *ci = findpcall(L); | 452 | CallInfo *ci = findpcall(L); |
453 | if (ci == NULL) return 0; /* no recovery point */ | 453 | if (ci == NULL) return 0; /* no recovery point */ |
454 | /* "finish" luaD_pcall */ | 454 | /* "finish" luaD_pcall */ |
455 | oldtop = restorestack(L, ci->u.c.oldtop); | 455 | oldtop = restorestack(L, ci->u.c.extra); |
456 | luaF_close(L, oldtop); | 456 | luaF_close(L, oldtop); |
457 | seterrorobj(L, status, oldtop); | 457 | seterrorobj(L, status, oldtop); |
458 | L->ci = ci; | 458 | L->ci = ci; |
@@ -501,11 +501,11 @@ static void resume (lua_State *L, void *ud) { | |||
501 | if (isLua(ci)) /* yielded inside a hook? */ | 501 | if (isLua(ci)) /* yielded inside a hook? */ |
502 | luaV_execute(L); /* just continue running Lua code */ | 502 | luaV_execute(L); /* just continue running Lua code */ |
503 | else { /* 'common' yield */ | 503 | else { /* 'common' yield */ |
504 | ci->func = restorestack(L, ci->u.c.extra); | ||
504 | if (ci->u.c.k != NULL) { /* does it have a continuation? */ | 505 | if (ci->u.c.k != NULL) { /* does it have a continuation? */ |
505 | int n; | 506 | int n; |
506 | ci->u.c.status = LUA_YIELD; /* 'default' status */ | 507 | ci->u.c.status = LUA_YIELD; /* 'default' status */ |
507 | ci->callstatus |= CIST_YIELDED; | 508 | ci->callstatus |= CIST_YIELDED; |
508 | ci->func = restorestack(L, ci->u.c.oldtop); | ||
509 | lua_unlock(L); | 509 | lua_unlock(L); |
510 | n = (*ci->u.c.k)(L); /* call continuation */ | 510 | n = (*ci->u.c.k)(L); /* call continuation */ |
511 | lua_lock(L); | 511 | lua_lock(L); |
@@ -565,11 +565,10 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k) { | |||
565 | api_check(L, k == NULL, "hooks cannot continue after yielding"); | 565 | api_check(L, k == NULL, "hooks cannot continue after yielding"); |
566 | } | 566 | } |
567 | else { | 567 | else { |
568 | if ((ci->u.c.k = k) != NULL) { /* is there a continuation? */ | 568 | if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ |
569 | ci->u.c.ctx = ctx; /* save context */ | 569 | ci->u.c.ctx = ctx; /* save context */ |
570 | ci->u.c.oldtop = savestack(L, ci->func); /* save current 'func' */ | 570 | ci->u.c.extra = savestack(L, ci->func); /* save current 'func' */ |
571 | } | 571 | ci->func = L->top - nresults - 1; /* protect stack below results */ |
572 | ci->func = L->top - nresults - 1; /* protect stack slots below */ | ||
573 | luaD_throw(L, LUA_YIELD); | 572 | luaD_throw(L, LUA_YIELD); |
574 | } | 573 | } |
575 | lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */ | 574 | lua_assert(ci->callstatus & CIST_HOOKED); /* must be inside a hook */ |