commit 079facab40542ff2e6be9ecc254fd148772b47c9
parent 4c5d7b2dddeb853b61489d02b738572eb29cb323
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 5 Apr 2004 11:42:55 -0300
ensures own top is corrected after calling function with multiple results
Diffstat:
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/lapi.c b/lapi.c
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.c,v 2.4 2004/03/09 17:34:35 roberto Exp roberto $
+** $Id: lapi.c,v 2.5 2004/03/23 17:07:34 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -56,7 +56,7 @@ const char lua_ident[] =
static TValue *luaA_index (lua_State *L, int idx) {
if (idx > 0) {
TValue *o = L->base + (idx - 1);
- api_check(L, idx <= L->stack_last - L->base);
+ api_check(L, idx <= L->ci->top - L->base);
if (o >= L->top) return cast(TValue *, &luaO_nilobject);
else return o;
}
@@ -698,12 +698,18 @@ LUA_API int lua_setfenv (lua_State *L, int idx) {
** `load' and `call' functions (run Lua code)
*/
+
+#define adjuststack(L,nres) \
+ { if (nres == LUA_MULTRET && L->top >= L->ci->top) L->ci->top = L->top; }
+
+
LUA_API void lua_call (lua_State *L, int nargs, int nresults) {
StkId func;
lua_lock(L);
api_checknelems(L, nargs+1);
func = L->top - (nargs+1);
luaD_call(L, func, nresults);
+ adjuststack(L, nresults);
lua_unlock(L);
}
@@ -740,6 +746,7 @@ LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) {
c.func = L->top - (nargs+1); /* function to be called */
c.nresults = nresults;
status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
+ adjuststack(L, nresults);
lua_unlock(L);
return status;
}