| 262 | |
| 263 | |
| 264 | int luaD_precall (lua_State *L, StkId func, int nresults) { |
| 265 | LClosure *cl; |
| 266 | ptrdiff_t funcr; |
| 267 | if (!ttisfunction(func)) /* `func' is not a function? */ |
| 268 | func = tryfuncTM(L, func); /* check the `function' tag method */ |
| 269 | funcr = savestack(L, func); |
| 270 | cl = &clvalue(func)->l; |
| 271 | L->ci->savedpc = L->savedpc; |
| 272 | if (!cl->isC) { /* Lua function? prepare its call */ |
| 273 | CallInfo *ci; |
| 274 | StkId st, base; |
| 275 | Proto *p = cl->p; |
| 276 | luaD_checkstack(L, p->maxstacksize); |
| 277 | func = restorestack(L, funcr); |
| 278 | if (!p->is_vararg) { /* no varargs? */ |
| 279 | base = func + 1; |
| 280 | if (L->top > base + p->numparams) |
| 281 | L->top = base + p->numparams; |
| 282 | } |
| 283 | else { /* vararg function */ |
| 284 | int nargs = cast_int(L->top - func) - 1; |
| 285 | base = adjust_varargs(L, p, nargs); |
| 286 | func = restorestack(L, funcr); /* previous call may change the stack */ |
| 287 | } |
| 288 | ci = inc_ci(L); /* now `enter' new function */ |
| 289 | ci->func = func; |
| 290 | L->base = ci->base = base; |
| 291 | ci->top = L->base + p->maxstacksize; |
| 292 | lua_assert(ci->top <= L->stack_last); |
| 293 | L->savedpc = p->code; /* starting point */ |
| 294 | ci->tailcalls = 0; |
| 295 | ci->nresults = nresults; |
| 296 | for (st = L->top; st < ci->top; st++) |
| 297 | setnilvalue(st); |
| 298 | L->top = ci->top; |
| 299 | if (L->hookmask & LUA_MASKCALL) { |
| 300 | L->savedpc++; /* hooks assume 'pc' is already incremented */ |
| 301 | luaD_callhook(L, LUA_HOOKCALL, -1); |
| 302 | L->savedpc--; /* correct 'pc' */ |
| 303 | } |
| 304 | return PCRLUA; |
| 305 | } |
| 306 | else { /* if is a C function, call it */ |
| 307 | CallInfo *ci; |
| 308 | int n; |
| 309 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
| 310 | ci = inc_ci(L); /* now `enter' new function */ |
| 311 | ci->func = restorestack(L, funcr); |
| 312 | L->base = ci->base = ci->func + 1; |
| 313 | ci->top = L->top + LUA_MINSTACK; |
| 314 | lua_assert(ci->top <= L->stack_last); |
| 315 | ci->nresults = nresults; |
| 316 | if (L->hookmask & LUA_MASKCALL) |
| 317 | luaD_callhook(L, LUA_HOOKCALL, -1); |
| 318 | lua_unlock(L); |
| 319 | n = (*curr_func(L)->c.f)(L); /* do the actual call */ |
| 320 | lua_lock(L); |
| 321 | if (n < 0) /* yielding? */ |
no test coverage detected