From 079facab40542ff2e6be9ecc254fd148772b47c9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 5 Apr 2004 11:43:17 -0300 Subject: [PATCH] ensures own top is corrected after calling function with multiple results --- lapi.c | 11 +++++++++-- 1 file 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 @@ /* -** $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; }