aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-03-10 14:14:37 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-03-10 14:14:37 -0300
commitba484b9eb16dd62a7c3a5400a66eb952b654d3f0 (patch)
tree31692ddf85265e5a46eab0cd55a0b0757a225e68 /lapi.c
parentf9d015523ef48266cea37e13717c223c16941b23 (diff)
downloadlua-ba484b9eb16dd62a7c3a5400a66eb952b654d3f0.tar.gz
lua-ba484b9eb16dd62a7c3a5400a66eb952b654d3f0.tar.bz2
lua-ba484b9eb16dd62a7c3a5400a66eb952b654d3f0.zip
yielding across lua_call (first version)
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/lapi.c b/lapi.c
index ea4d0f1f..60dc19f5 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.69 2009/02/18 17:20:56 roberto Exp roberto $ 2** $Id: lapi.c,v 2.70 2009/02/19 17:15:13 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*/
@@ -757,21 +757,25 @@ LUA_API int lua_setfenv (lua_State *L, int idx) {
757*/ 757*/
758 758
759 759
760#define adjustresults(L,nres) \
761 { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; }
762
763
764#define checkresults(L,na,nr) \ 760#define checkresults(L,na,nr) \
765 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)))
766 762
767 763
768LUA_API void lua_call (lua_State *L, int nargs, int nresults) { 764LUA_API void lua_callcont (lua_State *L, int nargs, int nresults,
765 lua_CFunction cont) {
769 StkId func; 766 StkId func;
770 lua_lock(L); 767 lua_lock(L);
768 /* cannot use continuations inside hooks */
769 api_check(L, cont == NULL || !isLua(L->ci));
771 api_checknelems(L, nargs+1); 770 api_checknelems(L, nargs+1);
772 checkresults(L, nargs, nresults); 771 checkresults(L, nargs, nresults);
773 func = L->top - (nargs+1); 772 func = L->top - (nargs+1);
774 luaD_call(L, func, nresults); 773 if (cont) {
774 L->ci->u.c.cont = cont;
775 luaD_call(L, func, nresults, 1);
776 }
777 else
778 luaD_call(L, func, nresults, 0);
775 adjustresults(L, nresults); 779 adjustresults(L, nresults);
776 lua_unlock(L); 780 lua_unlock(L);
777} 781}
@@ -789,7 +793,7 @@ struct CallS { /* data to `f_call' */
789 793
790static void f_call (lua_State *L, void *ud) { 794static void f_call (lua_State *L, void *ud) {
791 struct CallS *c = cast(struct CallS *, ud); 795 struct CallS *c = cast(struct CallS *, ud);
792 luaD_call(L, c->func, c->nresults); 796 luaD_call(L, c->func, c->nresults, 0);
793} 797}
794 798
795 799
@@ -835,7 +839,7 @@ static void f_Ccall (lua_State *L, void *ud) {
835 api_incr_top(L); 839 api_incr_top(L);
836 setpvalue(L->top, c->ud); /* push only argument */ 840 setpvalue(L->top, c->ud); /* push only argument */
837 api_incr_top(L); 841 api_incr_top(L);
838 luaD_call(L, L->top - 2, 0); 842 luaD_call(L, L->top - 2, 0, 0);
839} 843}
840 844
841 845