| 206 | |
| 207 | |
| 208 | static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { |
| 209 | int i; |
| 210 | int nfixargs = p->numparams; |
| 211 | Table *htab = NULL; |
| 212 | StkId base, fixed; |
| 213 | for (; actual < nfixargs; ++actual) |
| 214 | setnilvalue(L->top++); |
| 215 | #if defined(LUA_COMPAT_VARARG) |
| 216 | if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */ |
| 217 | int nvar = actual - nfixargs; /* number of extra arguments */ |
| 218 | lua_assert(p->is_vararg & VARARG_HASARG); |
| 219 | luaC_checkGC(L); |
| 220 | luaD_checkstack(L, p->maxstacksize); |
| 221 | htab = luaH_new(L, nvar, 1); /* create `arg' table */ |
| 222 | for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ |
| 223 | setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i); |
| 224 | /* store counter in field `n' */ |
| 225 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); |
| 226 | } |
| 227 | #endif |
| 228 | /* move fixed parameters to final position */ |
| 229 | fixed = L->top - actual; /* first fixed argument */ |
| 230 | base = L->top; /* final position of first argument */ |
| 231 | for (i=0; i<nfixargs; i++) { |
| 232 | setobjs2s(L, L->top++, fixed+i); |
| 233 | setnilvalue(fixed+i); |
| 234 | } |
| 235 | /* add `arg' parameter */ |
| 236 | if (htab) { |
| 237 | sethvalue(L, L->top++, htab); |
| 238 | lua_assert(iswhite(obj2gco(htab))); |
| 239 | } |
| 240 | return base; |
| 241 | } |
| 242 | |
| 243 | |
| 244 | static StkId tryfuncTM (lua_State *L, StkId func) { |
no test coverage detected