MCPcopy Create free account
hub / github.com/Tencent/sluaunreal / funcnamefromcode

Function funcnamefromcode

Plugins/slua_unreal/External/lua/ldebug.cpp:489–533  ·  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

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

Callers 1

getfuncnameFunction · 0.85

Calls 3

currentpcFunction · 0.85
getobjnameFunction · 0.85
GFunction · 0.85

Tested by

no test coverage detected