示例#1
0
static const char *getobjname (Proto *p, int lastpc, int reg,
                               const char **name) {
    int pc;
    *name = luaF_getlocalname(p, reg + 1, lastpc);
    if (*name)  /* is a local? */
        return "local";
    /* else try symbolic execution */
    pc = findsetreg(p, lastpc, reg);
    if (pc != -1) {  /* could find instruction? */
        Instruction i = p->code[pc];
        OpCode op = GET_OPCODE(i);
        switch (op) {
        case OP_MOVE: {
            int b = GETARG_B(i);  /* move from 'b' to 'a' */
            if (b < GETARG_A(i))
                return getobjname(p, pc, b, name);  /* get name for 'b' */
            break;
        }
        case OP_GETTABUP:
        case OP_GETTABLE: {
            int k = GETARG_C(i);  /* key index */
            int t = GETARG_B(i);  /* table index */
            const char *vn = (op == OP_GETTABLE)  /* name of indexed variable */
                             ? luaF_getlocalname(p, t + 1, pc)
                             : upvalname(p, t);
            kname(p, pc, k, name);
            return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
        }
        case OP_GETUPVAL: {
            *name = upvalname(p, GETARG_B(i));
            return "upvalue";
        }
        case OP_LOADK:
        case OP_LOADKX: {
            int b = (op == OP_LOADK) ? GETARG_Bx(i)
                    : GETARG_Ax(p->code[pc + 1]);
            if (ttisstring(&p->k[b])) {
                *name = svalue(&p->k[b]);
                return "constant";
            }
            break;
        }
        case OP_SELF: {
            int k = GETARG_C(i);  /* key index */
            kname(p, pc, k, name);
            return "method";
        }
        default:
            break;  /* go through to return NULL */
        }
    }
    return NULL;  /* could not find reasonable name */
}
示例#2
0
文件: ldebug.c 项目: crazii/mameplus
static const char *getupvalname (CallInfo *ci, const TValue *o,
									const char **name) {
	LClosure *c = ci_func(ci);
	int i;
	for (i = 0; i < c->nupvalues; i++) {
	if (c->upvals[i]->v == o) {
		*name = upvalname(c->p, i);
		return "upvalue";
	}
	}
	return NULL;
}