Search in sources :

Example 71 with LuaValue

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

the class CoroutineLib method call.

public LuaValue call(LuaValue modname, LuaValue env) {
    globals = env.checkglobals();
    LuaTable coroutine = new LuaTable();
    coroutine.set("create", new create());
    coroutine.set("resume", new resume());
    coroutine.set("running", new running());
    coroutine.set("status", new status());
    coroutine.set("yield", new yield());
    coroutine.set("wrap", new wrap());
    env.set("coroutine", coroutine);
    env.get("package").get("loaded").set("coroutine", coroutine);
    return coroutine;
}
Also used : LuaTable(org.luaj.vm2.LuaTable)

Example 72 with LuaValue

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

the class DebugLib method callHook.

void callHook(LuaValue type, LuaValue arg) {
    LuaThread t = globals.running;
    t.inhook = true;
    try {
        t.hookfunc.call(type, arg);
    } catch (LuaError e) {
        throw e;
    } catch (RuntimeException e) {
        throw new LuaError(e);
    } finally {
        t.inhook = false;
    }
}
Also used : LuaError(org.luaj.vm2.LuaError) LuaThread(org.luaj.vm2.LuaThread)

Example 73 with LuaValue

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

the class IoLib method ioread.

private Varargs ioread(File f, Varargs args) throws IOException {
    int i, n = args.narg();
    LuaValue[] v = new LuaValue[n];
    LuaValue ai, vi;
    LuaString fmt;
    for (i = 0; i < n; ) {
        item: switch((ai = args.arg(i + 1)).type()) {
            case LuaValue.TNUMBER:
                vi = freadbytes(f, ai.toint());
                break item;
            case LuaValue.TSTRING:
                fmt = ai.checkstring();
                if (fmt.m_length == 2 && fmt.m_bytes[fmt.m_offset] == '*') {
                    switch(fmt.m_bytes[fmt.m_offset + 1]) {
                        case 'n':
                            vi = freadnumber(f);
                            break item;
                        case 'l':
                            vi = freadline(f);
                            break item;
                        case 'a':
                            vi = freadall(f);
                            break item;
                    }
                }
            default:
                return argerror(i + 1, "(invalid format)");
        }
        if ((v[i++] = vi).isnil())
            break;
    }
    return i == 0 ? NIL : varargsOf(v, 0, i);
}
Also used : LuaString(org.luaj.vm2.LuaString) LuaValue(org.luaj.vm2.LuaValue)

Example 74 with LuaValue

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

the class IoLib method call.

public LuaValue call(LuaValue modname, LuaValue env) {
    globals = env.checkglobals();
    // io lib functions
    LuaTable t = new LuaTable();
    bind(t, IoLibV.class, IO_NAMES);
    // create file methods table
    filemethods = new LuaTable();
    bind(filemethods, IoLibV.class, FILE_NAMES, FILE_CLOSE);
    // set up file metatable
    LuaTable mt = new LuaTable();
    bind(mt, IoLibV.class, new String[] { "__index" }, IO_INDEX);
    t.setmetatable(mt);
    // all functions link to library instance
    setLibInstance(t);
    setLibInstance(filemethods);
    setLibInstance(mt);
    // return the table
    env.set("io", t);
    env.get("package").get("loaded").set("io", t);
    return t;
}
Also used : LuaTable(org.luaj.vm2.LuaTable)

Example 75 with LuaValue

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

the class LibFunction method bind.

/**
     * Bind a set of library functions, with an offset
     * <p/>
     * An array of names is provided, and the first name is bound
     * with opcode = {@code firstopcode}, second with {@code firstopcode+1}, etc.
     *
     * @param env         The environment to apply to each bound function
     * @param factory     the Class to instantiate for each bound function
     * @param names       array of String names, one for each function.
     * @param firstopcode the first opcode to use
     * @see #bind(LuaValue, Class, String[])
     */
protected void bind(LuaValue env, Class factory, String[] names, int firstopcode) {
    try {
        for (int i = 0, n = names.length; i < n; i++) {
            LibFunction f = (LibFunction) factory.newInstance();
            f.opcode = firstopcode + i;
            f.name = names[i];
            env.set(f.name, f);
        }
    } catch (Exception e) {
        throw new LuaError("bind failed: " + e);
    }
}
Also used : LuaError(org.luaj.vm2.LuaError)

Aggregations

LuaValue (org.luaj.vm2.LuaValue)51 LuaTable (org.luaj.vm2.LuaTable)35 Varargs (org.luaj.vm2.Varargs)12 LuaString (org.luaj.vm2.LuaString)9 VarArgFunction (org.luaj.vm2.lib.VarArgFunction)7 UDView (com.taobao.luaview.userdata.ui.UDView)5 LuaFunction (org.luaj.vm2.LuaFunction)5 View (android.view.View)4 LuaError (org.luaj.vm2.LuaError)4 Point (android.graphics.Point)3 ILVView (com.taobao.luaview.view.interfaces.ILVView)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 JSONObject (org.json.JSONObject)3 HorizontalScrollView (android.widget.HorizontalScrollView)2 AerospikeException (com.aerospike.client.AerospikeException)2 UDLuaTable (com.taobao.luaview.userdata.base.UDLuaTable)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Field (java.lang.reflect.Field)2