diff options
author | Lua Team <team@lua.org> | 2012-06-08 12:00:00 +0000 |
---|---|---|
committer | repogen <> | 2012-06-08 12:00:00 +0000 |
commit | 8c898400a5ddff24ab5b69f79e2c70bab521511d (patch) | |
tree | b773255b1ed3e8785f713b4e7dcaf3de81237f4d | |
parent | 850623c5e6a01fa1e8541c03b123fe6e35e02feb (diff) | |
download | lua-github-8c898400a5ddff24ab5b69f79e2c70bab521511d.tar.gz |
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | doc/manual.html | 25 | ||||
-rw-r--r-- | src/lapi.c | 4 | ||||
-rw-r--r-- | src/ldo.c | 8 | ||||
-rw-r--r-- | src/lstate.h | 5 | ||||
-rw-r--r-- | src/lvm.c | 19 |
6 files changed, 41 insertions, 22 deletions
@@ -1,5 +1,5 @@ -This is Lua 5.2.1, released on 01 Jun 2012. +This is Lua 5.2.1, released on 08 Jun 2012. For installation instructions, license details, and further information about Lua, see doc/readme.html. diff --git a/doc/manual.html b/doc/manual.html index fd6d988a..4ba084df 100644 --- a/doc/manual.html +++ b/doc/manual.html @@ -33,7 +33,7 @@ Freely available under the terms of the <!-- ====================================================================== --> <p> -<!-- $Id: manual.of,v 1.98 2012/05/31 13:01:09 roberto Exp $ --> +<!-- $Id: manual.of,v 1.99 2012/06/08 15:30:20 roberto Exp $ --> @@ -3350,7 +3350,7 @@ opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>. <hr><h3><a name="lua_getctx"><code>lua_getctx</code></a></h3><p> <span class="apii">[-0, +0, –]</span> -<pre>int lua_getctx (lua_State *L, int *ctx);</pre> +<pre>int lua_getctx (lua_State *L, int *ctx);</pre> <p> This function is called by a continuation function (see <a href="#4.7">§4.7</a>) @@ -4856,7 +4856,7 @@ and <hr><h3><a name="lua_typename"><code>lua_typename</code></a></h3><p> <span class="apii">[-0, +0, –]</span> -<pre>const char *lua_typename (lua_State *L, int tp);</pre> +<pre>const char *lua_typename (lua_State *L, int tp);</pre> <p> Returns the name of the type encoded by the value <code>tp</code>, @@ -4940,7 +4940,7 @@ and pushes them onto the stack <code>to</code>. <hr><h3><a name="lua_yield"><code>lua_yield</code></a></h3><p> <span class="apii">[-?, +?, –]</span> -<pre>int lua_yield (lua_State *L, int nresults);</pre> +<pre>int lua_yield (lua_State *L, int nresults);</pre> <p> This function is equivalent to <a href="#lua_yieldk"><code>lua_yieldk</code></a>, @@ -4955,7 +4955,7 @@ the function calling <code>lua_yield</code>. <hr><h3><a name="lua_yieldk"><code>lua_yieldk</code></a></h3><p> <span class="apii">[-?, +?, –]</span> -<pre>int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k);</pre> +<pre>int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k);</pre> <p> Yields a coroutine. @@ -5354,8 +5354,17 @@ this execution occurs without any calls to hooks. <p> -Hook functions cannot yield -(that is, call <a href="#lua_yieldk"><code>lua_yieldk</code></a> or <a href="#lua_yield"><code>lua_yield</code></a>). +Hook functions cannot have continuations, +that is, they cannot call <a href="#lua_yieldk"><code>lua_yieldk</code></a>, +<a href="#lua_pcallk"><code>lua_pcallk</code></a>, or <a href="#lua_callk"><code>lua_callk</code></a> with a non-null <code>k</code>. + + +<p> +Hook functions can yield under the following conditions: +Only count and line events can yield +and they cannot yield any value; +to yield a hook function must finish its execution +calling <a href="#lua_yield"><code>lua_yield</code></a> with <code>nresults</code> equal to zero. @@ -10406,7 +10415,7 @@ Here is the complete syntax of Lua in extended BNF. <HR> <SMALL CLASS="footer"> Last update: -Fri Jun 1 12:38:38 BRT 2012 +Fri Jun 8 16:13:40 BRT 2012 </SMALL> <!-- Last change: revised for Lua 5.2.1 @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.163 2012/05/23 15:42:27 roberto Exp $ +** $Id: lapi.c,v 2.164 2012/06/08 15:14:04 roberto Exp $ ** Lua API ** See Copyright Notice in lua.h */ @@ -950,7 +950,7 @@ LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, ci->u.c.k = k; /* save continuation */ ci->u.c.ctx = ctx; /* save context */ /* save information for error recovery */ - ci->u.c.extra = savestack(L, c.func); + ci->extra = savestack(L, c.func); ci->u.c.old_allowhook = L->allowhook; ci->u.c.old_errfunc = L->errfunc; L->errfunc = func; @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 2.104 2012/05/08 13:53:33 roberto Exp $ +** $Id: ldo.c,v 2.105 2012/06/08 15:14:04 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -451,7 +451,7 @@ static int recover (lua_State *L, int status) { CallInfo *ci = findpcall(L); if (ci == NULL) return 0; /* no recovery point */ /* "finish" luaD_pcall */ - oldtop = restorestack(L, ci->u.c.extra); + oldtop = restorestack(L, ci->extra); luaF_close(L, oldtop); seterrorobj(L, status, oldtop); L->ci = ci; @@ -498,10 +498,10 @@ static void resume (lua_State *L, void *ud) { resume_error(L, "cannot resume dead coroutine", firstArg); else { /* resuming from previous yield */ L->status = LUA_OK; + ci->func = restorestack(L, ci->extra); if (isLua(ci)) /* yielded inside a hook? */ luaV_execute(L); /* just continue running Lua code */ else { /* 'common' yield */ - ci->func = restorestack(L, ci->u.c.extra); if (ci->u.c.k != NULL) { /* does it have a continuation? */ int n; ci->u.c.status = LUA_YIELD; /* 'default' status */ @@ -563,13 +563,13 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k) { luaG_runerror(L, "attempt to yield from outside a coroutine"); } L->status = LUA_YIELD; + ci->extra = savestack(L, ci->func); /* save current 'func' */ if (isLua(ci)) { /* inside a hook? */ api_check(L, k == NULL, "hooks cannot continue after yielding"); } else { if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ ci->u.c.ctx = ctx; /* save context */ - ci->u.c.extra = savestack(L, ci->func); /* save current 'func' */ ci->func = L->top - nresults - 1; /* protect stack below results */ luaD_throw(L, LUA_YIELD); } diff --git a/src/lstate.h b/src/lstate.h index 936afc2d..29f810ba 100644 --- a/src/lstate.h +++ b/src/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 2.80 2012/05/22 17:50:39 roberto Exp $ +** $Id: lstate.h,v 2.81 2012/06/08 15:14:04 roberto Exp $ ** Global State ** See Copyright Notice in lua.h */ @@ -72,6 +72,7 @@ typedef struct CallInfo { struct CallInfo *previous, *next; /* dynamic call link */ short nresults; /* expected number of results from this function */ lu_byte callstatus; + ptrdiff_t extra; union { struct { /* only for Lua functions */ StkId base; /* base for this function */ @@ -81,7 +82,6 @@ typedef struct CallInfo { int ctx; /* context info. in case of yields */ lua_CFunction k; /* continuation in case of yields */ ptrdiff_t old_errfunc; - ptrdiff_t extra; lu_byte old_allowhook; lu_byte status; } c; @@ -100,6 +100,7 @@ typedef struct CallInfo { #define CIST_YPCALL (1<<4) /* call is a yieldable protected call */ #define CIST_STAT (1<<5) /* call has an error status (pcall) */ #define CIST_TAIL (1<<6) /* call was tail called */ +#define CIST_HOOKYIELD (1<<7) /* last hook called yielded */ #define isLua(ci) ((ci)->callstatus & CIST_LUA) @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.151 2012/05/14 17:50:49 roberto Exp $ +** $Id: lvm.c,v 2.152 2012/06/08 15:14:04 roberto Exp $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -60,10 +60,15 @@ int luaV_tostring (lua_State *L, StkId obj) { static void traceexec (lua_State *L) { CallInfo *ci = L->ci; lu_byte mask = L->hookmask; - if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) { - resethookcount(L); - luaD_hook(L, LUA_HOOKCOUNT, -1); + int counthook = ((mask & LUA_MASKCOUNT) && L->hookcount == 0); + if (counthook) + resethookcount(L); /* reset count */ + if (ci->callstatus & CIST_HOOKYIELD) { /* called hook last time? */ + ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */ + return; /* do not call hook again (VM yielded, so it did not move) */ } + if (counthook) + luaD_hook(L, LUA_HOOKCOUNT, -1); /* call count hook */ if (mask & LUA_MASKLINE) { Proto *p = ci_func(ci)->p; int npc = pcRel(ci->u.l.savedpc, p); @@ -71,11 +76,15 @@ static void traceexec (lua_State *L) { if (npc == 0 || /* call linehook when enter a new function, */ ci->u.l.savedpc <= L->oldpc || /* when jump back (loop), or when */ newline != getfuncline(p, pcRel(L->oldpc, p))) /* enter a new line */ - luaD_hook(L, LUA_HOOKLINE, newline); + luaD_hook(L, LUA_HOOKLINE, newline); /* call line hook */ } L->oldpc = ci->u.l.savedpc; if (L->status == LUA_YIELD) { /* did hook yield? */ + if (counthook) + L->hookcount = 1; /* undo decrement to zero */ ci->u.l.savedpc--; /* undo increment (resume will increment it again) */ + ci->callstatus |= CIST_HOOKYIELD; /* mark that it yieled */ + ci->func = L->top - 1; /* protect stack below results */ luaD_throw(L, LUA_YIELD); } } |