MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / luaD_precall

Function luaD_precall

libraries/AP_Scripting/lua/src/ldo.c:422–480  ·  view source on GitHub ↗

** Prepares a function call: checks the stack, creates a new CallInfo ** entry, fills in the relevant information, calls hook if needed. ** If function is a C function, does the call, too. (Otherwise, leave ** the execution ('luaV_execute') to the caller, to allow stackless ** calls.) Returns true iff function has been executed (C function). */

Source from the content-addressed store, hash-verified

420** calls.) Returns true iff function has been executed (C function).
421*/
422int luaD_precall (lua_State *L, StkId func, int nresults) {
423 lua_CFunction f;
424 CallInfo *ci;
425 switch (ttype(func)) {
426 case LUA_TCCL: /* C closure */
427 f = clCvalue(func)->f;
428 goto Cfunc;
429 case LUA_TLCF: /* light C function */
430 f = fvalue(func);
431 Cfunc: {
432 int n; /* number of returns */
433 checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */
434 ci = next_ci(L); /* now 'enter' new function */
435 ci->nresults = nresults;
436 ci->func = func;
437 ci->top = L->top + LUA_MINSTACK;
438 lua_assert(ci->top <= L->stack_last);
439 ci->callstatus = 0;
440 if (L->hookmask & LUA_MASKCALL)
441 luaD_hook(L, LUA_HOOKCALL, -1);
442 lua_unlock(L);
443 n = (*f)(L); /* do the actual call */
444 lua_lock(L);
445 api_checknelems(L, n);
446 luaD_poscall(L, ci, L->top - n, n);
447 return 1;
448 }
449 case LUA_TLCL: { /* Lua function: prepare its call */
450 StkId base;
451 Proto *p = clLvalue(func)->p;
452 int n = cast_int(L->top - func) - 1; /* number of real arguments */
453 int fsize = p->maxstacksize; /* frame size */
454 checkstackp(L, fsize, func);
455 if (p->is_vararg)
456 base = adjust_varargs(L, p, n);
457 else { /* non vararg function */
458 for (; n < p->numparams; n++)
459 setnilvalue(L->top++); /* complete missing arguments */
460 base = func + 1;
461 }
462 ci = next_ci(L); /* now 'enter' new function */
463 ci->nresults = nresults;
464 ci->func = func;
465 ci->u.l.base = base;
466 L->top = ci->top = base + fsize;
467 lua_assert(ci->top <= L->stack_last);
468 ci->u.l.savedpc = p->code; /* starting point */
469 ci->callstatus = CIST_LUA;
470 if (L->hookmask & LUA_MASKCALL)
471 callhook(L, ci);
472 return 0;
473 }
474 default: { /* not a function */
475 checkstackp(L, 1, func); /* ensure space for metamethod */
476 tryfuncTM(L, func); /* try to get '__call' metamethod */
477 return luaD_precall(L, func, nresults); /* now it must be a function */
478 }
479 }

Callers 3

luaV_executeFunction · 0.85
luaD_callFunction · 0.85
resumeFunction · 0.85

Calls 5

luaD_hookFunction · 0.85
luaD_poscallFunction · 0.85
adjust_varargsFunction · 0.85
callhookFunction · 0.85
tryfuncTMFunction · 0.85

Tested by

no test coverage detected