MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / adjust_varargs

Function adjust_varargs

Source/Misc/lua/src/lua.c:5354–5386  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

luaD_precallFunction · 0.85

Calls 3

luaH_newFunction · 0.85
luaH_setnumFunction · 0.85
luaH_setstrFunction · 0.85

Tested by

no test coverage detected