Search in sources :

Example 6 with LuaError

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

the class LuanPhone method onTouch.

// / calls love.phone.touch(action,{id1,x1,y1,id2,x2,y2,...})
// / for action see also love.phone.MOTION_EVENT_ACTION_TYPE
// / you can define this callback similar to love.mousepressed to get detailed touch info
// / only if love.phone.enableTouchEvents() has been called
// / see http://developer.android.com/reference/android/view/MotionEvent.html for details about multitouch handling
public void onTouch(MotionEvent event) {
    if (!mbEnableTouchEvents)
        return;
    // http://stackoverflow.com/questions/362424/accessing-constructor-of-an-anonymous-class
    vm.FireEvent(new LoveVM.cLoveEvent() {

        MotionEvent event;

        public LoveVM.cLoveEvent MyInit(MotionEvent event) {
            this.event = event;
            return this;
        }

        public void Execute(LoveVM vm) {
            if (!vm.isInitDone())
                return;
            try {
                LuaTable t = new LuaTable();
                for (int i = 0; i < event.getPointerCount(); ++i) {
                    t.set(1 + i * 3 + 0, LuaValue.valueOf(event.getPointerId(i)));
                    t.set(1 + i * 3 + 1, LuaValue.valueOf(event.getX(i)));
                    t.set(1 + i * 3 + 2, LuaValue.valueOf(event.getY(i)));
                }
                vm.get_G().get("love").get("phone").get("touch").call(LuaValue.valueOf(event.getAction()), t);
            } catch (LuaError e) {
                vm.handleLuaError(e);
            }
        }
    }.MyInit(event));
}
Also used : LuaTable(org.luaj.vm2.LuaTable) LoveVM(net.schattenkind.androidLove.LoveVM) LuaError(org.luaj.vm2.LuaError) MotionEvent(android.view.MotionEvent)

Example 7 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, List<String> methods) {
    LuaTable env = new LuaTable();
    try {
        if (methods != null) {
            for (int i = 0; i < methods.size(); i++) {
                LibFunction f = factory.newInstance();
                f.opcode = i;
                f.method = null;
                f.name = methods.get(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)

Example 8 with LuaError

use of org.luaj.vm2.LuaError 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 9 with LuaError

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

Example 10 with LuaError

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

the class LexState method lexerror.

void lexerror(String msg, int token) {
    String cid = Lua.chunkid(source.tojstring());
    L.pushfstring(cid + ":" + linenumber + ": " + msg);
    if (token != 0)
        L.pushfstring("syntax error: " + msg + " near " + txtToken(token));
    // modified by song
    throw new LuaError(cid + ":" + linenumber + ": " + msg + " near " + txtToken(token));
}
Also used : LuaError(org.luaj.vm2.LuaError) LuaString(org.luaj.vm2.LuaString)

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