Search in sources :

Example 1 with UpValue

use of org.luaj.vm2.UpValue in project LuaViewSDK by alibaba.

the class DestroyUtil method onDestroyClosure.

public static void onDestroyClosure(LuaClosure closure) {
    if (closure != null) {
        if (closure.upValues != null) {
            UpValue upValue = null;
            for (int i = 0; i < closure.upValues.length; i++) {
                upValue = closure.upValues[i];
                // if (upValue != null && upValue.array != null) {
                // for (LuaValue value : upValue.array) {//destroy upvalues
                // if (value instanceof BaseUserdata) {//userdata destory
                // ((BaseUserdata) value).onDestroy();
                // } else if (value instanceof LuaTable) {//destroy table
                // onDestroyTable((LuaTable) value);
                // }
                // }
                // }
                closure.upValues[i] = null;
            }
            closure.upValues = null;
        }
    }
}
Also used : UpValue(org.luaj.vm2.UpValue)

Example 2 with UpValue

use of org.luaj.vm2.UpValue in project LuaViewSDK by alibaba.

the class DebugLib method getobjname.

// return NameWhat if found, null if not
public static NameWhat getobjname(Prototype p, int lastpc, int reg) {
    // currentpc(L, ci);
    int pc = lastpc;
    LuaString name = p.getlocalname(reg + 1, pc);
    if (name != null)
        /* is a local? */
        return new NameWhat(name.tojstring(), "local");
    /* else try symbolic execution */
    pc = findsetreg(p, lastpc, reg);
    if (pc != -1) {
        /* could find instruction? */
        int i = p.code[pc];
        switch(Lua.GET_OPCODE(i)) {
            case Lua.OP_MOVE:
                {
                    int a = Lua.GETARG_A(i);
                    int b = Lua.GETARG_B(i);
                    /* move from `b' to `a' */
                    if (b < a)
                        return getobjname(p, pc, b);
                    /* get name for `b' */
                    break;
                }
            case Lua.OP_GETTABUP:
            case Lua.OP_GETTABLE:
                {
                    int k = Lua.GETARG_C(i);
                    /* key index */
                    int t = Lua.GETARG_B(i);
                    /* table index */
                    LuaString vn = (Lua.GET_OPCODE(i) == Lua.OP_GETTABLE) ? /* name of indexed variable */
                    p.getlocalname(t + 1, pc) : (t < p.upvalues.length ? p.upvalues[t].name : QMARK);
                    name = kname(p, k);
                    return new NameWhat(name.tojstring(), vn != null && vn.eq_b(ENV) ? "global" : "field");
                }
            case Lua.OP_GETUPVAL:
                {
                    int u = Lua.GETARG_B(i);
                    /* upvalue index */
                    name = u < p.upvalues.length ? p.upvalues[u].name : QMARK;
                    return new NameWhat(name.tojstring(), "upvalue");
                }
            case Lua.OP_LOADK:
            case Lua.OP_LOADKX:
                {
                    int b = (Lua.GET_OPCODE(i) == Lua.OP_LOADK) ? Lua.GETARG_Bx(i) : Lua.GETARG_Ax(p.code[pc + 1]);
                    if (p.k[b].isstring()) {
                        name = p.k[b].strvalue();
                        return new NameWhat(name.tojstring(), "constant");
                    }
                    break;
                }
            case Lua.OP_SELF:
                {
                    int k = Lua.GETARG_C(i);
                    /* key index */
                    name = kname(p, k);
                    return new NameWhat(name.tojstring(), "method");
                }
            default:
                break;
        }
    }
    return null;
/* no useful name found */
}
Also used : LuaString(org.luaj.vm2.LuaString) LuaPrint(org.luaj.vm2.log.LuaPrint)

Example 3 with UpValue

use of org.luaj.vm2.UpValue in project LuaViewSDK by alibaba.

the class LexState method mainfunc.

/*
	** compiles the main function, which is a regular vararg function with an
	** upvalue named LUA_ENV
	*/
public void mainfunc(FuncState funcstate) {
    BlockCnt bl = new BlockCnt();
    open_func(funcstate, bl);
    fs.f.is_vararg = 1;
    /* main function is always vararg */
    expdesc v = new expdesc();
    v.init(VLOCAL, 0);
    /* create and... */
    fs.newupvalue(envn, v);
    /* ...set environment upvalue */
    next();
    /* read first token */
    statlist();
    /* parse main body */
    check(TK_EOS);
    close_func();
}
Also used : BlockCnt(org.luaj.vm2.compiler.FuncState.BlockCnt)

Example 4 with UpValue

use of org.luaj.vm2.UpValue in project LuaViewSDK by alibaba.

the class LuaPrint method buildHeader.

void buildHeader(Prototype f) {
    String s = String.valueOf(f.source);
    if (s.startsWith("@") || s.startsWith("="))
        s = s.substring(1);
    else if ("\033Lua".equals(s))
        s = "(bstring)";
    else
        s = "(string)";
    String a = (f.linedefined == 0) ? "main" : "function";
    ps.append("\n%" + a + " <" + s + ":" + f.linedefined + "," + f.lastlinedefined + "> (" + f.code.length + " instructions, " + f.code.length * 4 + " bytes at " + id(f) + ")\n");
    ps.append(f.numparams + " param, " + f.maxstacksize + " slot, " + f.upvalues.length + " upvalue, ");
    ps.append(f.locvars.length + " local, " + f.k.length + " constant, " + f.p.length + " function\n");
}
Also used : LuaString(org.luaj.vm2.LuaString)

Aggregations

LuaString (org.luaj.vm2.LuaString)2 UpValue (org.luaj.vm2.UpValue)1 BlockCnt (org.luaj.vm2.compiler.FuncState.BlockCnt)1 LuaPrint (org.luaj.vm2.log.LuaPrint)1