** returns true if function has been executed (C function) */
| 294 | ** returns true if function has been executed (C function) |
| 295 | */ |
| 296 | int luaD_precall (lua_State *L, StkId func, int nresults) { |
| 297 | lua_CFunction f; |
| 298 | CallInfo *ci; |
| 299 | int n; /* number of arguments (Lua) or returns (C) */ |
| 300 | ptrdiff_t funcr = savestack(L, func); |
| 301 | switch (ttype(func)) { |
| 302 | case LUA_TLCF: /* light C function */ |
| 303 | f = fvalue(func); |
| 304 | goto Cfunc; |
| 305 | case LUA_TCCL: { /* C closure */ |
| 306 | f = clCvalue(func)->f; |
| 307 | Cfunc: |
| 308 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
| 309 | ci = next_ci(L); /* now 'enter' new function */ |
| 310 | ci->nresults = nresults; |
| 311 | ci->func = restorestack(L, funcr); |
| 312 | ci->top = L->top + LUA_MINSTACK; |
| 313 | lua_assert(ci->top <= L->stack_last); |
| 314 | ci->callstatus = 0; |
| 315 | luaC_checkGC(L); /* stack grow uses memory */ |
| 316 | if (L->hookmask & LUA_MASKCALL) |
| 317 | luaD_hook(L, LUA_HOOKCALL, -1); |
| 318 | lua_unlock(L); |
| 319 | n = (*f)(L); /* do the actual call */ |
| 320 | lua_lock(L); |
| 321 | api_checknelems(L, n); |
| 322 | luaD_poscall(L, L->top - n); |
| 323 | return 1; |
| 324 | } |
| 325 | case LUA_TLCL: { /* Lua function: prepare its call */ |
| 326 | StkId base; |
| 327 | Proto *p = clLvalue(func)->p; |
| 328 | n = cast_int(L->top - func) - 1; /* number of real arguments */ |
| 329 | luaD_checkstack(L, p->maxstacksize); |
| 330 | for (; n < p->numparams; n++) |
| 331 | setnilvalue(L->top++); /* complete missing arguments */ |
| 332 | if (!p->is_vararg) { |
| 333 | func = restorestack(L, funcr); |
| 334 | base = func + 1; |
| 335 | } |
| 336 | else { |
| 337 | base = adjust_varargs(L, p, n); |
| 338 | func = restorestack(L, funcr); /* previous call can change stack */ |
| 339 | } |
| 340 | ci = next_ci(L); /* now 'enter' new function */ |
| 341 | ci->nresults = nresults; |
| 342 | ci->func = func; |
| 343 | ci->u.l.base = base; |
| 344 | ci->top = base + p->maxstacksize; |
| 345 | lua_assert(ci->top <= L->stack_last); |
| 346 | ci->u.l.savedpc = p->code; /* starting point */ |
| 347 | ci->callstatus = CIST_LUA; |
| 348 | L->top = ci->top; |
| 349 | luaC_checkGC(L); /* stack grow uses memory */ |
| 350 | if (L->hookmask & LUA_MASKCALL) |
| 351 | callhook(L, ci); |
| 352 | return 0; |
| 353 | } |
no test coverage detected