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

Function getobjname

third-party/lua-5.3.5/src/ldebug.c:431–482  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

429
430
431static const char *getobjname (Proto *p, int lastpc, int reg,
432 const char **name) {
433 int pc;
434 *name = luaF_getlocalname(p, reg + 1, lastpc);
435 if (*name) /* is a local? */
436 return "local";
437 /* else try symbolic execution */
438 pc = findsetreg(p, lastpc, reg);
439 if (pc != -1) { /* could find instruction? */
440 Instruction i = p->code[pc];
441 OpCode op = GET_OPCODE(i);
442 switch (op) {
443 case OP_MOVE: {
444 int b = GETARG_B(i); /* move from 'b' to 'a' */
445 if (b < GETARG_A(i))
446 return getobjname(p, pc, b, name); /* get name for 'b' */
447 break;
448 }
449 case OP_GETTABUP:
450 case OP_GETTABLE: {
451 int k = GETARG_C(i); /* key index */
452 int t = GETARG_B(i); /* table index */
453 const char *vn = (op == OP_GETTABLE) /* name of indexed variable */
454 ? luaF_getlocalname(p, t + 1, pc)
455 : upvalname(p, t);
456 kname(p, pc, k, name);
457 return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
458 }
459 case OP_GETUPVAL: {
460 *name = upvalname(p, GETARG_B(i));
461 return "upvalue";
462 }
463 case OP_LOADK:
464 case OP_LOADKX: {
465 int b = (op == OP_LOADK) ? GETARG_Bx(i)
466 : GETARG_Ax(p->code[pc + 1]);
467 if (ttisstring(&p->k[b])) {
468 *name = svalue(&p->k[b]);
469 return "constant";
470 }
471 break;
472 }
473 case OP_SELF: {
474 int k = GETARG_C(i); /* key index */
475 kname(p, pc, k, name);
476 return "method";
477 }
478 default: break; /* go through to return NULL */
479 }
480 }
481 return NULL; /* could not find reasonable name */
482}
483
484
485/*

Callers 3

knameFunction · 0.70
funcnamefromcodeFunction · 0.70
varinfoFunction · 0.70

Calls 4

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

Tested by

no test coverage detected