aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-04-05 11:43:17 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-04-05 11:43:17 -0300
commit079facab40542ff2e6be9ecc254fd148772b47c9 (patch)
tree5aaa4ba8153e5e19455c186d5f23c2c9dc1ee166
parent4c5d7b2dddeb853b61489d02b738572eb29cb323 (diff)
downloadlua-079facab40542ff2e6be9ecc254fd148772b47c9.tar.gz
lua-079facab40542ff2e6be9ecc254fd148772b47c9.tar.bz2
lua-079facab40542ff2e6be9ecc254fd148772b47c9.zip
ensures own top is corrected after calling function with multiple results
-rw-r--r--lapi.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/lapi.c b/lapi.c
index ba25b89e..37e9ce6b 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.4 2004/03/09 17:34:35 roberto Exp roberto $ 2** $Id: lapi.c,v 2.5 2004/03/23 17:07:34 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*/
@@ -56,7 +56,7 @@ const char lua_ident[] =
56static TValue *luaA_index (lua_State *L, int idx) { 56static TValue *luaA_index (lua_State *L, int idx) {
57 if (idx > 0) { 57 if (idx > 0) {
58 TValue *o = L->base + (idx - 1); 58 TValue *o = L->base + (idx - 1);
59 api_check(L, idx <= L->stack_last - L->base); 59 api_check(L, idx <= L->ci->top - L->base);
60 if (o >= L->top) return cast(TValue *, &luaO_nilobject); 60 if (o >= L->top) return cast(TValue *, &luaO_nilobject);
61 else return o; 61 else return o;
62 } 62 }
@@ -698,12 +698,18 @@ LUA_API int lua_setfenv (lua_State *L, int idx) {
698** `load' and `call' functions (run Lua code) 698** `load' and `call' functions (run Lua code)
699*/ 699*/
700 700
701
702#define adjuststack(L,nres) \
703 { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; }
704
705
701LUA_API void lua_call (lua_State *L, int nargs, int nresults) { 706LUA_API void lua_call (lua_State *L, int nargs, int nresults) {
702 StkId func; 707 StkId func;
703 lua_lock(L); 708 lua_lock(L);
704 api_checknelems(L, nargs+1); 709 api_checknelems(L, nargs+1);
705 func = L->top - (nargs+1); 710 func = L->top - (nargs+1);
706 luaD_call(L, func, nresults); 711 luaD_call(L, func, nresults);
712 adjuststack(L, nresults);
707 lua_unlock(L); 713 lua_unlock(L);
708} 714}
709 715
@@ -740,6 +746,7 @@ LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) {
740 c.func = L->top - (nargs+1); /* function to be called */ 746 c.func = L->top - (nargs+1); /* function to be called */
741 c.nresults = nresults; 747 c.nresults = nresults;
742 status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func); 748 status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
749 adjuststack(L, nresults);
743 lua_unlock(L); 750 lua_unlock(L);
744 return status; 751 return status;
745} 752}