From ffff9a49da35b8b90d48f5419c9c5e0402f803af Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 30 Sep 2010 14:21:31 -0300 Subject: [PATCH] 'nresults' in CallInfo now refers to number of results that the current function returns (and not what it expects from a call) --- ldo.c | 7 ++++--- lstate.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ldo.c b/ldo.c index 0003e6c8..1b675264 100644 --- a/ldo.c +++ b/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 2.87 2010/05/05 18:49:56 roberto Exp roberto $ +** $Id: ldo.c,v 2.88 2010/06/04 13:06:15 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -299,7 +299,6 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { if (!ttisfunction(func)) /* `func' is not a function? */ func = tryfuncTM(L, func); /* check the `function' tag method */ funcr = savestack(L, func); - L->ci->nresults = nresults; if (ttislcf(func)) { /* light C function? */ f = fvalue(func); /* get it */ goto isCfunc; /* go to call it */ @@ -312,6 +311,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { isCfunc: /* call C function 'f' */ luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ ci = next_ci(L); /* now 'enter' new function */ + ci->nresults = nresults; ci->func = restorestack(L, funcr); ci->top = L->top + LUA_MINSTACK; lua_assert(ci->top <= L->stack_last); @@ -341,6 +341,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { else /* vararg function */ base = adjust_varargs(L, p, nargs); ci = next_ci(L); /* now 'enter' new function */ + ci->nresults = nresults; ci->func = func; ci->u.l.base = base; ci->top = base + p->maxstacksize; @@ -368,8 +369,8 @@ int luaD_poscall (lua_State *L, StkId firstResult) { L->oldpc = ci->previous->u.l.savedpc; /* 'oldpc' for caller function */ } res = ci->func; /* res == final position of 1st result */ - L->ci = ci = ci->previous; /* back to caller */ wanted = ci->nresults; + L->ci = ci = ci->previous; /* back to caller */ /* move results to correct place */ for (i = wanted; i != 0 && firstResult < L->top; i--) setobjs2s(L, res++, firstResult++); diff --git a/lstate.h b/lstate.h index 0d834801..656b04fb 100644 --- a/lstate.h +++ b/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 2.65 2010/05/03 17:39:48 roberto Exp roberto $ +** $Id: lstate.h,v 2.66 2010/09/03 14:14:01 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -72,7 +72,7 @@ typedef struct CallInfo { StkId func; /* function index in the stack */ StkId top; /* top for this function */ struct CallInfo *previous, *next; /* dynamic call link */ - short nresults; /* expected number of results from a call */ + short nresults; /* expected number of results from this function */ lu_byte callstatus; union { struct { /* only for Lua functions */