** 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. */
| 597 | ** "metamethod") and sets '*name' to point to the name. |
| 598 | */ |
| 599 | static const char *funcnamefromcode (lua_State *L, CallInfo *ci, |
| 600 | const char **name) { |
| 601 | TMS tm = (TMS)0; /* (initial value avoids warnings) */ |
| 602 | const Proto *p = ci_func(ci)->p; /* calling function */ |
| 603 | int pc = currentpc(ci); /* calling instruction index */ |
| 604 | Instruction i = p->code[pc]; /* calling instruction */ |
| 605 | if (ci->callstatus & CIST_HOOKED) { /* was it called inside a hook? */ |
| 606 | *name = "?"; |
| 607 | return "hook"; |
| 608 | } |
| 609 | switch (GET_OPCODE(i)) { |
| 610 | case OP_CALL: |
| 611 | case OP_TAILCALL: |
| 612 | return getobjname(p, pc, GETARG_A(i), name); /* get function name */ |
| 613 | case OP_TFORCALL: { /* for iterator */ |
| 614 | *name = "for iterator"; |
| 615 | return "for iterator"; |
| 616 | } |
| 617 | /* other instructions can do calls through metamethods */ |
| 618 | case OP_SELF: case OP_GETTABUP: case OP_GETTABLE: |
| 619 | case OP_GETI: case OP_GETFIELD: |
| 620 | tm = TM_INDEX; |
| 621 | break; |
| 622 | case OP_SETTABUP: case OP_SETTABLE: case OP_SETI: case OP_SETFIELD: |
| 623 | tm = TM_NEWINDEX; |
| 624 | break; |
| 625 | case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: { |
| 626 | tm = cast(TMS, GETARG_C(i)); |
| 627 | break; |
| 628 | } |
| 629 | case OP_UNM: tm = TM_UNM; break; |
| 630 | case OP_BNOT: tm = TM_BNOT; break; |
| 631 | case OP_LEN: tm = TM_LEN; break; |
| 632 | case OP_CONCAT: tm = TM_CONCAT; break; |
| 633 | case OP_EQ: tm = TM_EQ; break; |
| 634 | case OP_LT: case OP_LE: case OP_LTI: case OP_LEI: |
| 635 | *name = "order"; /* '<=' can call '__lt', etc. */ |
| 636 | return "metamethod"; |
| 637 | case OP_CLOSE: case OP_RETURN: |
| 638 | *name = "close"; |
| 639 | return "metamethod"; |
| 640 | default: |
| 641 | return NULL; /* cannot find a reasonable name */ |
| 642 | } |
| 643 | *name = getstr(G(L)->tmname[tm]) + 2; |
| 644 | return "metamethod"; |
| 645 | } |
| 646 | |
| 647 | /* }====================================================== */ |
| 648 |
no test coverage detected