** 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. */
| 592 | ** "metamethod") and sets '*name' to point to the name. |
| 593 | */ |
| 594 | static const char *funcnamefromcode (lua_State *L, const Proto *p, |
| 595 | int pc, const char **name) { |
| 596 | TMS tm = (TMS)0; /* (initial value avoids warnings) */ |
| 597 | Instruction i = p->code[pc]; /* calling instruction */ |
| 598 | switch (GET_OPCODE(i)) { |
| 599 | case OP_CALL: |
| 600 | case OP_TAILCALL: |
| 601 | return getobjname(p, pc, GETARG_A(i), name); /* get function name */ |
| 602 | case OP_TFORCALL: { /* for iterator */ |
| 603 | *name = "for iterator"; |
| 604 | return "for iterator"; |
| 605 | } |
| 606 | /* other instructions can do calls through metamethods */ |
| 607 | case OP_SELF: case OP_GETTABUP: case OP_GETTABLE: |
| 608 | case OP_GETI: case OP_GETFIELD: |
| 609 | tm = TM_INDEX; |
| 610 | break; |
| 611 | case OP_SETTABUP: case OP_SETTABLE: case OP_SETI: case OP_SETFIELD: |
| 612 | tm = TM_NEWINDEX; |
| 613 | break; |
| 614 | case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: { |
| 615 | tm = cast(TMS, GETARG_C(i)); |
| 616 | break; |
| 617 | } |
| 618 | case OP_UNM: tm = TM_UNM; break; |
| 619 | case OP_BNOT: tm = TM_BNOT; break; |
| 620 | case OP_LEN: tm = TM_LEN; break; |
| 621 | case OP_CONCAT: tm = TM_CONCAT; break; |
| 622 | case OP_EQ: tm = TM_EQ; break; |
| 623 | /* no cases for OP_EQI and OP_EQK, as they don't call metamethods */ |
| 624 | case OP_LT: case OP_LTI: case OP_GTI: tm = TM_LT; break; |
| 625 | case OP_LE: case OP_LEI: case OP_GEI: tm = TM_LE; break; |
| 626 | case OP_CLOSE: case OP_RETURN: tm = TM_CLOSE; break; |
| 627 | default: |
| 628 | return NULL; /* cannot find a reasonable name */ |
| 629 | } |
| 630 | *name = getstr(G(L)->tmname[tm]) + 2; |
| 631 | return "metamethod"; |
| 632 | } |
| 633 | |
| 634 | |
| 635 | /* |
no test coverage detected