diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-03-23 11:26:12 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-03-23 11:26:12 -0300 |
commit | 6d0ae11c576106b490a53215c3f227b65ace2776 (patch) | |
tree | fcb09763cf7f81036ed277e65dc5c967d77deef4 /lapi.c | |
parent | 3ca739b418243544ecc1098e34c71f2378bad915 (diff) | |
download | lua-6d0ae11c576106b490a53215c3f227b65ace2776.tar.gz lua-6d0ae11c576106b490a53215c3f227b65ace2776.tar.bz2 lua-6d0ae11c576106b490a53215c3f227b65ace2776.zip |
'context' added to suspendable calls
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.70 2009/02/19 17:15:13 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.71 2009/03/10 17:14:37 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -761,17 +761,28 @@ LUA_API int lua_setfenv (lua_State *L, int idx) { | |||
761 | api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na))) | 761 | api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na))) |
762 | 762 | ||
763 | 763 | ||
764 | LUA_API void lua_callcont (lua_State *L, int nargs, int nresults, | 764 | LUA_API int lua_getctx (lua_State *L, int *ctx) { |
765 | lua_CFunction cont) { | 765 | if (L->ci->callstatus & CIST_CTX) { /* call has ctx? */ |
766 | *ctx = L->ci->u.c.ctx; | ||
767 | return LUA_YIELD; | ||
768 | } | ||
769 | else return LUA_OK; | ||
770 | } | ||
771 | |||
772 | |||
773 | LUA_API void lua_callk (lua_State *L, int nargs, int nresults, int ctx, | ||
774 | lua_CFunction k) { | ||
766 | StkId func; | 775 | StkId func; |
767 | lua_lock(L); | 776 | lua_lock(L); |
768 | /* cannot use continuations inside hooks */ | 777 | /* cannot use continuations inside hooks */ |
769 | api_check(L, cont == NULL || !isLua(L->ci)); | 778 | api_check(L, k == NULL || !isLua(L->ci)); |
770 | api_checknelems(L, nargs+1); | 779 | api_checknelems(L, nargs+1); |
771 | checkresults(L, nargs, nresults); | 780 | checkresults(L, nargs, nresults); |
772 | func = L->top - (nargs+1); | 781 | func = L->top - (nargs+1); |
773 | if (cont) { | 782 | if (k != NULL) { |
774 | L->ci->u.c.cont = cont; | 783 | L->ci->u.c.k = k; |
784 | L->ci->u.c.ctx = ctx; | ||
785 | L->ci->callstatus |= CIST_CTX; | ||
775 | luaD_call(L, func, nresults, 1); | 786 | luaD_call(L, func, nresults, 1); |
776 | } | 787 | } |
777 | else | 788 | else |