Search in sources :

Example 16 with LuaString

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

the class LuaC method luaY_parser.

/**
 * Parse the input
 */
private Prototype luaY_parser(InputStream z, String name, boolean standardSyntax) throws IOException {
    LexState lexstate = new LexState(this, z, standardSyntax);
    FuncState funcstate = new FuncState();
    // lexstate.buff = buff;
    lexstate.fs = funcstate;
    lexstate.setinput(this, z.read(), z, (LuaString) LuaValue.valueOf(name));
    /* main func. is always vararg */
    funcstate.f = new Prototype();
    funcstate.f.source = (LuaString) LuaValue.valueOf(name);
    lexstate.mainfunc(funcstate);
    LuaC._assert(funcstate.prev == null);
    /* all scopes should be correctly finished */
    LuaC._assert(lexstate.dyd == null || (lexstate.dyd.n_actvar == 0 && lexstate.dyd.n_gt == 0 && lexstate.dyd.n_label == 0));
    return funcstate.f;
}
Also used : Prototype(org.luaj.vm2.Prototype)

Example 17 with LuaString

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

the class Str method charString.

public static LuaString charString(String image) {
    String s = image.substring(1, image.length() - 1);
    byte[] bytes = unquote(s);
    return LuaString.valueOf(bytes);
}
Also used : LuaString(org.luaj.vm2.LuaString)

Example 18 with LuaString

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

the class Str method longString.

public static LuaString longString(String image) {
    int i = image.indexOf('[', image.indexOf('[') + 1) + 1;
    String s = image.substring(i, image.length() - i);
    byte[] b = iso88591bytes(s);
    return LuaString.valueOf(b);
}
Also used : LuaString(org.luaj.vm2.LuaString)

Example 19 with LuaString

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

the class DumpState method dumpConstants.

void dumpConstants(final Prototype f) throws IOException {
    final LuaValue[] k = f.k;
    int i, n = k.length;
    dumpInt(n);
    for (i = 0; i < n; i++) {
        final LuaValue o = k[i];
        switch(o.type()) {
            case LuaValue.TNIL:
                writer.write(LuaValue.TNIL);
                break;
            case LuaValue.TBOOLEAN:
                writer.write(LuaValue.TBOOLEAN);
                dumpChar(o.toboolean() ? 1 : 0);
                break;
            case LuaValue.TNUMBER:
                switch(NUMBER_FORMAT) {
                    case NUMBER_FORMAT_FLOATS_OR_DOUBLES:
                        writer.write(LuaValue.TNUMBER);
                        dumpDouble(o.todouble());
                        break;
                    case NUMBER_FORMAT_INTS_ONLY:
                        if (!ALLOW_INTEGER_CASTING && !o.isint())
                            throw new java.lang.IllegalArgumentException("not an integer: " + o);
                        writer.write(LuaValue.TNUMBER);
                        dumpInt(o.toint());
                        break;
                    case NUMBER_FORMAT_NUM_PATCH_INT32:
                        if (o.isint()) {
                            writer.write(LuaValue.TINT);
                            dumpInt(o.toint());
                        } else {
                            writer.write(LuaValue.TNUMBER);
                            dumpDouble(o.todouble());
                        }
                        break;
                    default:
                        throw new IllegalArgumentException("number format not supported: " + NUMBER_FORMAT);
                }
                break;
            case LuaValue.TSTRING:
                writer.write(LuaValue.TSTRING);
                dumpString((LuaString) o);
                break;
            default:
                throw new IllegalArgumentException("bad type for " + o);
        }
    }
    n = f.p.length;
    dumpInt(n);
    for (i = 0; i < n; i++) dumpFunction(f.p[i]);
}
Also used : LuaValue(org.luaj.vm2.LuaValue)

Example 20 with LuaString

use of org.luaj.vm2.LuaString 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)

Aggregations

LuaString (org.luaj.vm2.LuaString)25 LuaValue (org.luaj.vm2.LuaValue)5 Prototype (org.luaj.vm2.Prototype)3 Buffer (org.luaj.vm2.Buffer)2 LuaPrint (org.luaj.vm2.log.LuaPrint)2 LocVars (org.luaj.vm2.LocVars)1 Upvaldesc (org.luaj.vm2.Upvaldesc)1 BlockCnt (org.luaj.vm2.compiler.FuncState.BlockCnt)1