** 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. ** Bits CIST_CCMT in status count how many _call metamethods were ** invoked and how many corresponding extra arguments were pushed. ** (This count will be saved in the 'callstatus' of the call). ** Raise a
| 521 | ** Raise an error if this counter overflows. |
| 522 | */ |
| 523 | static unsigned tryfuncTM (lua_State *L, StkId func, unsigned status) { |
| 524 | const TValue *tm; |
| 525 | StkId p; |
| 526 | tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); |
| 527 | if (l_unlikely(ttisnil(tm))) /* no metamethod? */ |
| 528 | luaG_callerror(L, s2v(func)); |
| 529 | for (p = L->top.p; p > func; p--) /* open space for metamethod */ |
| 530 | setobjs2s(L, p, p-1); |
| 531 | L->top.p++; /* stack space pre-allocated by the caller */ |
| 532 | setobj2s(L, func, tm); /* metamethod is the new function to be called */ |
| 533 | if ((status & MAX_CCMT) == MAX_CCMT) /* is counter full? */ |
| 534 | luaG_runerror(L, "'__call' chain too long"); |
| 535 | return status + (1u << CIST_CCMT); /* increment counter */ |
| 536 | } |
| 537 | |
| 538 | |
| 539 | /* Generic case for 'moveresult' */ |
no test coverage detected