MCPcopy Create free account
hub / github.com/PlutoLang/Pluto / funcnamefromcode

Function funcnamefromcode

src/ldebug.cpp:633–671  ·  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

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

Callers 1

funcnamefromcallFunction · 0.85

Calls 1

getobjnameFunction · 0.85

Tested by

no test coverage detected