Search in sources :

Example 1 with LuaError

use of org.luaj.vm2.LuaError in project pixel-dungeon-remix by NYRDS.

the class LuaEngine method module.

@Nullable
public static LuaTable module(String module, String fallback) {
    LuaValue luaModule = getEngine().call("require", module);
    if (luaModule.istable()) {
        return luaModule.checktable();
    }
    EventCollector.logEvent("LuaError", "failed to load lua module:", module);
    luaModule = getEngine().call("require", fallback);
    if (luaModule.istable()) {
        return luaModule.checktable();
    }
    EventCollector.logEvent("LuaError", "failed to load fallback lua module:", fallback);
    return null;
}
Also used : LuaValue(org.luaj.vm2.LuaValue) Nullable(android.support.annotation.Nullable)

Example 2 with LuaError

use of org.luaj.vm2.LuaError in project pixel-dungeon-remix by NYRDS.

the class LuaEngine method call.

public LuaValue call(String method, Object arg1, Object arg2) {
    try {
        LuaValue methodForData = globals.get(method);
        methodForData.call(CoerceJavaToLua.coerce(arg1), CoerceJavaToLua.coerce(arg2));
    } catch (LuaError err) {
        reportLuaError(err);
    }
    return LuaValue.NIL;
}
Also used : LuaError(org.luaj.vm2.LuaError) LuaValue(org.luaj.vm2.LuaValue)

Example 3 with LuaError

use of org.luaj.vm2.LuaError in project love-android by hagish.

the class LoveConfig method loadFromFileStream.

public void loadFromFileStream(InputStream configFileInputStream) throws IOException {
    LuaTable g = JsePlatform.debugGlobals();
    g.set("love", new LuaTable());
    try {
        LoadState.load(configFileInputStream, "conf.lua", g).call();
    } catch (LuaError e) {
    // ~ vm.handleLuaError(e);
    // ignored
    }
    LuaValue conf = LuaUtils.getFromTableByPath(g, "love.conf");
    if (!conf.equals(LuaValue.NIL)) {
        LuaTable t = new LuaTable();
        t.set("modules", new LuaTable());
        t.set("screen", new LuaTable());
        try {
            conf.call(t);
        } catch (LuaError e) {
        // ~ vm.handleLuaError(e);
        // ignored
        }
        loadFromLuaTable(t);
    }
}
Also used : LuaTable(org.luaj.vm2.LuaTable) LuaError(org.luaj.vm2.LuaError) LuaValue(org.luaj.vm2.LuaValue)

Example 4 with LuaError

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

the class LuaViewManager method bindMethods.

/**
 * bind lua functions using method
 *
 * @param factory
 * @param methods
 * @return
 */
public static LuaTable bindMethods(Class<? extends LibFunction> factory, List<Method> methods) {
    LuaTable env = new LuaTable();
    try {
        if (methods != null) {
            for (int i = 0; i < methods.size(); i++) {
                LibFunction f = factory.newInstance();
                f.opcode = -1;
                f.method = methods.get(i);
                f.name = methods.get(i).getName();
                env.set(f.name, f);
            }
        }
    } catch (Exception e) {
        throw new LuaError("[Bind Failed] " + e);
    } finally {
        return env;
    }
}
Also used : LuaTable(org.luaj.vm2.LuaTable) LuaError(org.luaj.vm2.LuaError) LibFunction(org.luaj.vm2.lib.LibFunction)

Example 5 with LuaError

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

the class LuaViewManager method bind.

/**
 * bind lua functions using opcode
 *
 * @param factory
 * @param methods
 * @return
 */
public static LuaTable bind(Class<? extends LibFunction> factory, String[] methods) {
    LuaTable env = new LuaTable();
    try {
        if (methods != null) {
            for (int i = 0; i < methods.length; i++) {
                LibFunction f = factory.newInstance();
                f.opcode = i;
                f.method = null;
                f.name = methods[i];
                env.set(f.name, f);
            }
        }
    } catch (Exception e) {
        throw new LuaError("[Bind Failed] " + e);
    } finally {
        return env;
    }
}
Also used : LuaTable(org.luaj.vm2.LuaTable) LuaError(org.luaj.vm2.LuaError) LibFunction(org.luaj.vm2.lib.LibFunction)

Aggregations

LuaError (org.luaj.vm2.LuaError)11 LuaTable (org.luaj.vm2.LuaTable)5 LuaValue (org.luaj.vm2.LuaValue)4 LibFunction (org.luaj.vm2.lib.LibFunction)3 Field (java.lang.reflect.Field)2 Nullable (android.support.annotation.Nullable)1 MotionEvent (android.view.MotionEvent)1 LoveVM (net.schattenkind.androidLove.LoveVM)1 LuaString (org.luaj.vm2.LuaString)1 LuaThread (org.luaj.vm2.LuaThread)1