| 5352 | |
| 5353 | |
| 5354 | static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { |
| 5355 | int i; |
| 5356 | int nfixargs = p->numparams; |
| 5357 | Table *htab = NULL; |
| 5358 | StkId base, fixed; |
| 5359 | for (; actual < nfixargs; ++actual) |
| 5360 | setnilvalue(L->top++); |
| 5361 | #if defined(LUA_COMPAT_VARARG) |
| 5362 | if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */ |
| 5363 | int nvar = actual - nfixargs; /* number of extra arguments */ |
| 5364 | lua_assert(p->is_vararg & VARARG_HASARG); |
| 5365 | luaC_checkGC(L); |
| 5366 | htab = luaH_new(L, nvar, 1); /* create `arg' table */ |
| 5367 | for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ |
| 5368 | setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i); |
| 5369 | /* store counter in field `n' */ |
| 5370 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); |
| 5371 | } |
| 5372 | #endif |
| 5373 | /* move fixed parameters to final position */ |
| 5374 | fixed = L->top - actual; /* first fixed argument */ |
| 5375 | base = L->top; /* final position of first argument */ |
| 5376 | for (i=0; i<nfixargs; i++) { |
| 5377 | setobjs2s(L, L->top++, fixed+i); |
| 5378 | setnilvalue(fixed+i); |
| 5379 | } |
| 5380 | /* add `arg' parameter */ |
| 5381 | if (htab) { |
| 5382 | sethvalue(L, L->top++, htab); |
| 5383 | lua_assert(iswhite(obj2gco(htab))); |
| 5384 | } |
| 5385 | return base; |
| 5386 | } |
| 5387 | |
| 5388 | |
| 5389 | static StkId tryfuncTM (lua_State *L, StkId func) { |
no test coverage detected