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

Function funcnamefromcode

lib/lua/src/ldebug.c:611–649  ·  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

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

Callers 1

funcnamefromcallFunction · 0.85

Calls 2

getobjnameFunction · 0.85
GFunction · 0.50

Tested by

no test coverage detected