MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / funcnamefromcode

Function funcnamefromcode

third-party/lua-5.5.0/src/ldebug.c:615–653  ·  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

613** "metamethod") and sets '*name' to point to the name.
614*/
615static const char *funcnamefromcode (lua_State *L, const Proto *p,
616 int pc, const char **name) {
617 TMS tm = (TMS)0; /* (initial value avoids warnings) */
618 Instruction i = p->code[pc]; /* calling instruction */
619 switch (GET_OPCODE(i)) {
620 case OP_CALL:
621 case OP_TAILCALL:
622 return getobjname(p, pc, GETARG_A(i), name); /* get function name */
623 case OP_TFORCALL: { /* for iterator */
624 *name = "for iterator";
625 return "for iterator";
626 }
627 /* other instructions can do calls through metamethods */
628 case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:
629 case OP_GETI: case OP_GETFIELD:
630 tm = TM_INDEX;
631 break;
632 case OP_SETTABUP: case OP_SETTABLE: case OP_SETI: case OP_SETFIELD:
633 tm = TM_NEWINDEX;
634 break;
635 case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: {
636 tm = cast(TMS, GETARG_C(i));
637 break;
638 }
639 case OP_UNM: tm = TM_UNM; break;
640 case OP_BNOT: tm = TM_BNOT; break;
641 case OP_LEN: tm = TM_LEN; break;
642 case OP_CONCAT: tm = TM_CONCAT; break;
643 case OP_EQ: tm = TM_EQ; break;
644 /* no cases for OP_EQI and OP_EQK, as they don't call metamethods */
645 case OP_LT: case OP_LTI: case OP_GTI: tm = TM_LT; break;
646 case OP_LE: case OP_LEI: case OP_GEI: tm = TM_LE; break;
647 case OP_CLOSE: case OP_RETURN: tm = TM_CLOSE; break;
648 default:
649 return NULL; /* cannot find a reasonable name */
650 }
651 *name = getshrstr(G(L)->tmname[tm]) + 2;
652 return "metamethod";
653}
654
655
656/*

Callers 1

funcnamefromcallFunction · 0.70

Calls 1

getobjnameFunction · 0.70

Tested by

no test coverage detected