| 5003 | |
| 5004 | |
| 5005 | static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, |
| 5006 | const char **name) { |
| 5007 | if (isLua(ci)) { /* a Lua function? */ |
| 5008 | Proto *p = ci_func(ci)->l.p; |
| 5009 | int pc = currentpc(L, ci); |
| 5010 | Instruction i; |
| 5011 | *name = luaF_getlocalname(p, stackpos+1, pc); |
| 5012 | if (*name) /* is a local? */ |
| 5013 | return "local"; |
| 5014 | i = symbexec(p, pc, stackpos); /* try symbolic execution */ |
| 5015 | lua_assert(pc != -1); |
| 5016 | switch (GET_OPCODE(i)) { |
| 5017 | case OP_GETGLOBAL: { |
| 5018 | int g = GETARG_Bx(i); /* global index */ |
| 5019 | lua_assert(ttisstring(&p->k[g])); |
| 5020 | *name = svalue(&p->k[g]); |
| 5021 | return "global"; |
| 5022 | } |
| 5023 | case OP_MOVE: { |
| 5024 | int a = GETARG_A(i); |
| 5025 | int b = GETARG_B(i); /* move from `b' to `a' */ |
| 5026 | if (b < a) |
| 5027 | return getobjname(L, ci, b, name); /* get name for `b' */ |
| 5028 | break; |
| 5029 | } |
| 5030 | case OP_GETTABLE: { |
| 5031 | int k = GETARG_C(i); /* key index */ |
| 5032 | *name = kname(p, k); |
| 5033 | return "field"; |
| 5034 | } |
| 5035 | case OP_GETUPVAL: { |
| 5036 | int u = GETARG_B(i); /* upvalue index */ |
| 5037 | *name = p->upvalues ? getstr(p->upvalues[u]) : "?"; |
| 5038 | return "upvalue"; |
| 5039 | } |
| 5040 | case OP_SELF: { |
| 5041 | int k = GETARG_C(i); /* key index */ |
| 5042 | *name = kname(p, k); |
| 5043 | return "method"; |
| 5044 | } |
| 5045 | default: break; |
| 5046 | } |
| 5047 | } |
| 5048 | return NULL; /* no useful name found */ |
| 5049 | } |
| 5050 | |
| 5051 | |
| 5052 | static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { |
no test coverage detected