MCPcopy Create free account
hub / github.com/DFHack/dfhack / funcnamefromcode

Function funcnamefromcode

depends/lua/src/ldebug.c:492–536  ·  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

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

Callers 1

getfuncnameFunction · 0.85

Calls 3

currentpcFunction · 0.85
getobjnameFunction · 0.85
castFunction · 0.85

Tested by

no test coverage detected