MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / funcnamefromcode

Function funcnamefromcode

3rd/lua-5.4.3/src/ldebug.c:593–637  ·  view source on GitHub ↗

** Try to find a name for a function based on the code that called it. ** (Only works when function was called by a Lua function.) ** Returns what the name is (e.g., "for iterator", "method", ** "metamethod") and sets '*name' to point to the name. */

Source from the content-addressed store, hash-verified

591** "metamethod") and sets '*name' to point to the name.
592*/
593static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
594 const char **name) {
595 TMS tm = (TMS)0; /* (initial value avoids warnings) */
596 const Proto *p = ci_func(ci)->p; /* calling function */
597 int pc = currentpc(ci); /* calling instruction index */
598 Instruction i = p->code[pc]; /* calling instruction */
599 if (ci->callstatus & CIST_HOOKED) { /* was it called inside a hook? */
600 *name = "?";
601 return "hook";
602 }
603 switch (GET_OPCODE(i)) {
604 case OP_CALL:
605 case OP_TAILCALL:
606 return getobjname(p, pc, GETARG_A(i), name); /* get function name */
607 case OP_TFORCALL: { /* for iterator */
608 *name = "for iterator";
609 return "for iterator";
610 }
611 /* other instructions can do calls through metamethods */
612 case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:
613 case OP_GETI: case OP_GETFIELD:
614 tm = TM_INDEX;
615 break;
616 case OP_SETTABUP: case OP_SETTABLE: case OP_SETI: case OP_SETFIELD:
617 tm = TM_NEWINDEX;
618 break;
619 case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: {
620 tm = cast(TMS, GETARG_C(i));
621 break;
622 }
623 case OP_UNM: tm = TM_UNM; break;
624 case OP_BNOT: tm = TM_BNOT; break;
625 case OP_LEN: tm = TM_LEN; break;
626 case OP_CONCAT: tm = TM_CONCAT; break;
627 case OP_EQ: tm = TM_EQ; break;
628 /* no cases for OP_EQI and OP_EQK, as they don't call metamethods */
629 case OP_LT: case OP_LTI: case OP_GTI: tm = TM_LT; break;
630 case OP_LE: case OP_LEI: case OP_GEI: tm = TM_LE; break;
631 case OP_CLOSE: case OP_RETURN: tm = TM_CLOSE; break;
632 default:
633 return NULL; /* cannot find a reasonable name */
634 }
635 *name = getstr(G(L)->tmname[tm]) + 2;
636 return "metamethod";
637}
638
639/* }====================================================== */
640

Callers 2

getfuncnameFunction · 0.85
luaG_callerrorFunction · 0.85

Calls 2

currentpcFunction · 0.85
getobjnameFunction · 0.85

Tested by

no test coverage detected