aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/ldo.c b/ldo.c
index fcec993e..3f81b4ae 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.30 2005/08/22 18:54:49 roberto Exp roberto $ 2** $Id: ldo.c,v 2.31 2005/08/22 19:58:29 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -205,19 +205,17 @@ void luaD_callhook (lua_State *L, int event, int line) {
205} 205}
206 206
207 207
208static StkId adjust_varargs (lua_State *L, int nfixargs, int actual, 208static StkId adjust_varargs (lua_State *L, Proto *p, int actual) {
209 int style) {
210 int i; 209 int i;
210 int nfixargs = p->numparams;
211 Table *htab = NULL; 211 Table *htab = NULL;
212 StkId base, fixed; 212 StkId base, fixed;
213 if (actual < nfixargs) { 213 for (; actual < nfixargs; ++actual)
214 for (; actual < nfixargs; ++actual) 214 setnilvalue(L->top++);
215 setnilvalue(L->top++);
216 }
217#if defined(LUA_COMPAT_VARARG) 215#if defined(LUA_COMPAT_VARARG)
218 if (style & VARARG_NEEDSARG) { /* compatibility with old-style vararg */ 216 if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */
219 int nvar = actual - nfixargs; /* number of extra arguments */ 217 int nvar = actual - nfixargs; /* number of extra arguments */
220 lua_assert(style & VARARG_HASARG); 218 lua_assert(p->is_vararg & VARARG_HASARG);
221 luaC_checkGC(L); 219 luaC_checkGC(L);
222 htab = luaH_new(L, nvar, 1); /* create `arg' table */ 220 htab = luaH_new(L, nvar, 1); /* create `arg' table */
223 for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ 221 for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */
@@ -276,16 +274,14 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
276 CallInfo *ci; 274 CallInfo *ci;
277 StkId st, base; 275 StkId st, base;
278 Proto *p = cl->p; 276 Proto *p = cl->p;
279 if (p->is_vararg) { /* varargs? */ 277 luaD_checkstack(L, p->maxstacksize);
280 int nargs = cast(int, L->top - restorestack(L, funcr)) - 1; 278 func = restorestack(L, funcr);
281 luaD_checkstack(L, p->maxstacksize + nargs); 279 if (!p->is_vararg) /* no varargs? */
282 base = adjust_varargs(L, p->numparams, nargs, p->is_vararg);
283 func = restorestack(L, funcr);
284 }
285 else {
286 luaD_checkstack(L, p->maxstacksize);
287 func = restorestack(L, funcr);
288 base = func + 1; 280 base = func + 1;
281 else { /* vararg function */
282 int nargs = cast(int, L->top - func) - 1;
283 base = adjust_varargs(L, p, nargs);
284 func = restorestack(L, funcr); /* previous call may change the stack */
289 } 285 }
290 ci = inc_ci(L); /* now `enter' new function */ 286 ci = inc_ci(L); /* now `enter' new function */
291 ci->func = func; 287 ci->func = func;