MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / getobjname

Function getobjname

third-party/lua-5.2.4/src/ldebug.c:408–459  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

406
407
408static const char *getobjname (Proto *p, int lastpc, int reg,
409 const char **name) {
410 int pc;
411 *name = luaF_getlocalname(p, reg + 1, lastpc);
412 if (*name) /* is a local? */
413 return "local";
414 /* else try symbolic execution */
415 pc = findsetreg(p, lastpc, reg);
416 if (pc != -1) { /* could find instruction? */
417 Instruction i = p->code[pc];
418 OpCode op = GET_OPCODE(i);
419 switch (op) {
420 case OP_MOVE: {
421 int b = GETARG_B(i); /* move from 'b' to 'a' */
422 if (b < GETARG_A(i))
423 return getobjname(p, pc, b, name); /* get name for 'b' */
424 break;
425 }
426 case OP_GETTABUP:
427 case OP_GETTABLE: {
428 int k = GETARG_C(i); /* key index */
429 int t = GETARG_B(i); /* table index */
430 const char *vn = (op == OP_GETTABLE) /* name of indexed variable */
431 ? luaF_getlocalname(p, t + 1, pc)
432 : upvalname(p, t);
433 kname(p, pc, k, name);
434 return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
435 }
436 case OP_GETUPVAL: {
437 *name = upvalname(p, GETARG_B(i));
438 return "upvalue";
439 }
440 case OP_LOADK:
441 case OP_LOADKX: {
442 int b = (op == OP_LOADK) ? GETARG_Bx(i)
443 : GETARG_Ax(p->code[pc + 1]);
444 if (ttisstring(&p->k[b])) {
445 *name = svalue(&p->k[b]);
446 return "constant";
447 }
448 break;
449 }
450 case OP_SELF: {
451 int k = GETARG_C(i); /* key index */
452 kname(p, pc, k, name);
453 return "method";
454 }
455 default: break; /* go through to return NULL */
456 }
457 }
458 return NULL; /* could not find reasonable name */
459}
460
461
462static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {

Callers 3

knameFunction · 0.70
getfuncnameFunction · 0.70
luaG_typeerrorFunction · 0.70

Calls 4

luaF_getlocalnameFunction · 0.70
findsetregFunction · 0.70
upvalnameFunction · 0.70
knameFunction · 0.70

Tested by

no test coverage detected