MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / tryfuncTM

Function tryfuncTM

lib/lua/src/ldo.c:412–424  ·  view source on GitHub ↗

** Check whether 'func' has a '__call' metafield. If so, put it in the ** stack, below original 'func', so that 'luaD_precall' can call it. Raise ** an error if there is no '__call' metafield. */

Source from the content-addressed store, hash-verified

410** an error if there is no '__call' metafield.
411*/
412static StkId tryfuncTM (lua_State *L, StkId func) {
413 const TValue *tm;
414 StkId p;
415 checkstackGCp(L, 1, func); /* space for metamethod */
416 tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); /* (after previous GC) */
417 if (l_unlikely(ttisnil(tm)))
418 luaG_callerror(L, s2v(func)); /* nothing to call */
419 for (p = L->top.p; p > func; p--) /* open space for metamethod */
420 setobjs2s(L, p, p-1);
421 L->top.p++; /* stack space pre-allocated by the caller */
422 setobj2s(L, func, tm); /* metamethod is the new function to be called */
423 return func;
424}
425
426
427/*

Callers 2

luaD_pretailcallFunction · 0.85
luaD_precallFunction · 0.85

Calls 2

luaT_gettmbyobjFunction · 0.85
luaG_callerrorFunction · 0.85

Tested by

no test coverage detected