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

Function funcnamefromcode

third-party/lua-5.3.5/src/ldebug.c:491–535  ·  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

489** "metamethod") and sets '*name' to point to the name.
490*/
491static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
492 const char **name) {
493 TMS tm = (TMS)0; /* (initial value avoids warnings) */
494 Proto *p = ci_func(ci)->p; /* calling function */
495 int pc = currentpc(ci); /* calling instruction index */
496 Instruction i = p->code[pc]; /* calling instruction */
497 if (ci->callstatus & CIST_HOOKED) { /* was it called inside a hook? */
498 *name = "?";
499 return "hook";
500 }
501 switch (GET_OPCODE(i)) {
502 case OP_CALL:
503 case OP_TAILCALL:
504 return getobjname(p, pc, GETARG_A(i), name); /* get function name */
505 case OP_TFORCALL: { /* for iterator */
506 *name = "for iterator";
507 return "for iterator";
508 }
509 /* other instructions can do calls through metamethods */
510 case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:
511 tm = TM_INDEX;
512 break;
513 case OP_SETTABUP: case OP_SETTABLE:
514 tm = TM_NEWINDEX;
515 break;
516 case OP_ADD: case OP_SUB: case OP_MUL: case OP_MOD:
517 case OP_POW: case OP_DIV: case OP_IDIV: case OP_BAND:
518 case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR: {
519 int offset = cast_int(GET_OPCODE(i)) - cast_int(OP_ADD); /* ORDER OP */
520 tm = cast(TMS, offset + cast_int(TM_ADD)); /* ORDER TM */
521 break;
522 }
523 case OP_UNM: tm = TM_UNM; break;
524 case OP_BNOT: tm = TM_BNOT; break;
525 case OP_LEN: tm = TM_LEN; break;
526 case OP_CONCAT: tm = TM_CONCAT; break;
527 case OP_EQ: tm = TM_EQ; break;
528 case OP_LT: tm = TM_LT; break;
529 case OP_LE: tm = TM_LE; break;
530 default:
531 return NULL; /* cannot find a reasonable name */
532 }
533 *name = getstr(G(L)->tmname[tm]);
534 return "metamethod";
535}
536
537/* }====================================================== */
538

Callers 1

getfuncnameFunction · 0.70

Calls 2

currentpcFunction · 0.70
getobjnameFunction · 0.70

Tested by

no test coverage detected