Search in sources :

Example 11 with LuaValue

use of org.luaj.vm2.LuaValue in project LogisticsPipes by RS485.

the class LPASMHookCC method onCCWrappedILuaObject.

public static LuaTable onCCWrappedILuaObject(final LuaTable table, final ILuaObject object) {
    if (object instanceof CCCommandWrapper) {
        LuaTable lpTable = new LPLuaTable((CCCommandWrapper) object);
        LuaValue k = LuaValue.NIL;
        while (true) {
            Varargs n = table.next(k);
            if ((k = n.arg1()).isnil()) {
                break;
            }
            LuaValue v = n.arg(2);
            lpTable.set(k, v);
        }
        ((CCCommandWrapper) object).table = lpTable;
        return lpTable;
    }
    return table;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) CCCommandWrapper(logisticspipes.proxy.cc.wrapper.CCCommandWrapper) Varargs(org.luaj.vm2.Varargs) LuaValue(org.luaj.vm2.LuaValue)

Example 12 with LuaValue

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

the class LuanAudio method InitLib.

public LuaTable InitLib() {
    mSoundPool = new SoundPool(kAudioChannels, AudioManager.STREAM_MUSIC, 0);
    LuaTable t = LuaValue.tableOf();
    LuaValue _G = vm.get_G();
    _G.set(sMetaName_LuanSource, LuanObjSource.CreateMetaTable(this));
    _G.set(sMetaName_LuanDecoder, LuanObjDecoder.CreateMetaTable(this));
    _G.set(sMetaName_LuanSoundData, LuanObjSoundData.CreateMetaTable(this));
    // numSources = love.audio.getNumSources( )
    t.set("getNumSources", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.audio.getNumSources");
            return LuaValue.ZERO;
        }
    });
    // fx, fy, fz, ux, uy, uz = love.audio.getOrientation( )
    t.set("getOrientation", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return varargsOf(new LuaValue[] { LuaNumber.valueOf(orientationForward.x), LuaNumber.valueOf(orientationForward.y), LuaNumber.valueOf(orientationForward.z), LuaNumber.valueOf(orientationUp.x), LuaNumber.valueOf(orientationUp.y), LuaNumber.valueOf(orientationUp.z) });
        }
    });
    // x, y, z = love.audio.getPosition( )
    t.set("getPosition", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return varargsOf(new LuaValue[] { LuaNumber.valueOf(position.x), LuaNumber.valueOf(position.y), LuaNumber.valueOf(position.z) });
        }
    });
    // x, y, z = love.audio.getVelocity( )
    t.set("getVelocity", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return varargsOf(new LuaValue[] { LuaNumber.valueOf(velocity.x), LuaNumber.valueOf(velocity.y), LuaNumber.valueOf(velocity.z) });
        }
    });
    // volume = love.audio.getVolume( )
    t.set("getVolume", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return varargsOf(new LuaValue[] { LuaNumber.valueOf(volume) });
        }
    });
    // source = love.audio.newSource( file, type )
    t.set("newSource", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            Log("love.audio.newSource params:" + ((args.narg() >= 1) ? getLuaTypeName(args.type(1)) : "notset") + "," + ((args.narg() >= 2) ? getLuaTypeName(args.type(2)) : "notset") + "," + ((args.narg() >= 3) ? getLuaTypeName(args.type(3)) : "notset") + "...");
            if (args.isstring(1)) {
                Log("love.audio.newSource(string,..)");
                String sFileName = args.checkjstring(1);
                String sType = IsArgSet(args, 2) ? args.checkjstring(2) : "static";
                return LuaValue.userdataOf(new LuanObjSource(LuanAudio.this, sFileName, sType), vm.get_G().get(sMetaName_LuanSource));
            }
            if (IsArgSet(args, 2) && args.isstring(2)) {
                Log("love.audio.newSource(???,string,..)");
                LuanObjDecoder decoder = (LuanObjDecoder) args.checkuserdata(1, LuanObjDecoder.class);
                String sType = args.checkjstring(2);
                return LuaValue.userdataOf(new LuanObjSource(LuanAudio.this, decoder, sType), vm.get_G().get(sMetaName_LuanSource));
            }
            LuanObjSoundData soundata = (LuanObjSoundData) args.checkuserdata(1, LuanObjSoundData.class);
            return LuaValue.userdataOf(new LuanObjSource(LuanAudio.this, soundata), vm.get_G().get(sMetaName_LuanSource));
        }
    });
    // love.audio.pause( )
    t.set("pause", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            // TODO
            vm.NotImplemented("love.audio.pause");
            return LuaValue.NONE;
        }
    });
    // / love.audio.play( source )
    // /Plays the specified Source.
    t.set("play", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            LuanObjSource src = (LuanObjSource) args.checkuserdata(1, LuanObjSource.class);
            src.play();
            return LuaValue.NONE;
        }
    });
    // love.audio.resume( )
    t.set("resume", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            // TODO
            vm.NotImplemented("love.audio.resume");
            return LuaValue.NONE;
        }
    });
    // love.audio.rewind( )
    t.set("rewind", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            // TODO
            vm.NotImplemented("love.audio.rewind");
            return LuaValue.NONE;
        }
    });
    // love.audio.setOrientation( fx, fy, fz, ux, uy, uz )
    t.set("setOrientation", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            orientationForward.x = args.arg(1).tofloat();
            orientationForward.y = args.arg(2).tofloat();
            orientationForward.z = args.arg(3).tofloat();
            orientationUp.x = args.arg(4).tofloat();
            orientationUp.y = args.arg(5).tofloat();
            orientationUp.z = args.arg(6).tofloat();
            notifySpatialChange();
            return LuaValue.NONE;
        }
    });
    // love.audio.setPosition( x, y, z )
    t.set("setPosition", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            position.x = args.arg(1).tofloat();
            position.y = args.arg(2).tofloat();
            position.z = args.arg(3).tofloat();
            notifySpatialChange();
            return LuaValue.NONE;
        }
    });
    // love.audio.setVelocity( x, y, z )
    t.set("setVelocity", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            position.x = args.arg(1).tofloat();
            position.y = args.arg(2).tofloat();
            position.z = args.arg(3).tofloat();
            notifySpatialChange();
            return LuaValue.NONE;
        }
    });
    // love.audio.setVolume( volume )
    t.set("setVolume", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            volume = args.arg(1).tofloat();
            // TODO
            vm.NotImplemented("love.audio.setVolume");
            return LuaValue.NONE;
        }
    });
    // love.audio.stop( )
    t.set("stop", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            // TODO
            vm.NotImplemented("love.audio.stop");
            return LuaValue.NONE;
        }
    });
    return t;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) Varargs(org.luaj.vm2.Varargs) LuaValue(org.luaj.vm2.LuaValue) SoundPool(android.media.SoundPool) VarArgFunction(org.luaj.vm2.lib.VarArgFunction)

Example 13 with LuaValue

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

the class LuanPhone method InitLib.

// ***** ***** ***** ***** ***** init
public LuaTable InitLib() {
    LuaTable t = LuaValue.tableOf();
    LuaValue _G = vm.get_G();
    _G.set(sMetaName_LuanSensor, LuanObjSensor.CreateMetaTable(this));
    // TODO: add phone/android/iphone specific api additions here, e.g. multi-touch event stuff, accelerometer, gravity sensor, maybe intent/running apps/network/start browser etc ?
    // / img = love.phone.newResourceImage(int iResID)
    // / loads an image from a resource id
    t.set("newResourceImage", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            int iResID = args.checkint(1);
            try {
                return LuaValue.userdataOf(new LuanObjImage(vm.getLuanGraphics(), iResID), vm.get_G().get(LuanGraphics.sMetaName_LuanImage));
            } catch (Exception e) {
                vm.handleError(e);
            }
            return LuaValue.NONE;
        }
    });
    // / source = love.phone.newResourceAudioSource(int iResID,string type)
    // / loads a sound/music/audio source from a resource id
    t.set("newResourceAudioSource", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            int iResID = args.checkint(1);
            try {
                String sType = IsArgSet(args, 2) ? args.checkjstring(2) : "static";
                return LuaValue.userdataOf(new LuanAudio.LuanObjSource(vm.getLuanAudio(), iResID, sType), vm.get_G().get(LuanAudio.sMetaName_LuanSource));
            } catch (Exception e) {
                vm.handleError(e);
            }
            return LuaValue.NONE;
        }
    });
    // TODO: newResourceFontTTF !!!
    // / source = love.phone.newResourceFontTTF(int iResID,int iSize)
    // / loads a ttf from ressource id
    // / String 	love.phone.getPackageName()
    // / Return the name of this application's package.
    t.set("getPackageName", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.valueOf(vm.getActivity().getPackageName());
        }
    });
    // / String 	love.phone.getResourceName(int iResID)
    // / Return the full name for a given resource identifier.
    t.set("getResourceName", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            try {
                return LuaValue.valueOf(vm.getResources().getResourceName(args.checkint(1)));
            } catch (Exception e) {
                vm.handleError(e);
            }
            return LuaValue.NONE;
        }
    });
    // / iResID = love.phone.getResourceID(String name, String defType, String defPackage)
    // / @name 	The name of the desired resource.
    // / @defType 	Optional default resource type to find, if "type/" is not included in the name. Can be null to require an explicit type.
    // / @defPackage 	Optional default package to find, if "package:" is not included in the name. Can be null to require an explicit package.
    t.set("getResourceID", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.valueOf(vm.getResources().getIdentifier(args.checkjstring(1), IsArgSet(args, 2) ? args.checkjstring(2) : null, IsArgSet(args, 3) ? args.checkjstring(3) : null));
        }
    });
    // int 	getIdentifier(String name, String defType, String defPackage)
    // / {sensor,..} = love.phone.getSensorList(iSensorType)
    // / see also love.phone.SENSOR_TYPE
    t.set("getSensorList", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            List<Sensor> myList = vm.getSensorManager().getSensorList(args.checkint(1));
            LuaTable t = new LuaTable(myList.size(), 0);
            for (int i = 0; i < myList.size(); ++i) t.set(i + 1, LuaValue.userdataOf(new LuanObjSensor(LuanPhone.this, myList.get(i)), vm.get_G().get(sMetaName_LuanSensor)));
            return t;
        }
    });
    // / sensor = love.phone.getDefaultSensor(iSensorType)
    // / see also love.phone.SENSOR_TYPE
    t.set("getDefaultSensor", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            Sensor s = vm.getSensorManager().getDefaultSensor(args.checkint(1));
            return LuaValue.userdataOf(new LuanObjSensor(LuanPhone.this, s), vm.get_G().get(sMetaName_LuanSensor));
        }
    });
    // / love.phone.enableTouchEvents()
    // / enable love.phone.touch(...) callback
    t.set("enableTouchEvents", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            mbEnableTouchEvents = true;
            return LuaValue.NONE;
        }
    });
    // / boolean love.phone.registerSensorListener(sensor,rate)
    // / Registers a SensorEventListener for the given sensor.
    t.set("registerSensorListener", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            LuanObjSensor s = (LuanObjSensor) args.checkuserdata(1, LuanObjSensor.class);
            int rate = args.checkint(2);
            return LuaValue.valueOf(vm.getSensorManager().registerListener(s, s.getSensor(), rate));
        }
    });
    // / love.phone.setBlockMainKey_Back(bBlocked)
    t.set("setBlockMainKey_Back", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            ((LoveAndroid) vm.getActivity()).setBlockMainKey_Back(args.checkboolean(1));
            return LuaValue.NONE;
        }
    });
    // / love.phone.setBlockMainKey_Menu(bBlocked)
    t.set("setBlockMainKey_Menu", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            ((LoveAndroid) vm.getActivity()).setBlockMainKey_Menu(args.checkboolean(1));
            return LuaValue.NONE;
        }
    });
    // / love.phone.setBlockMainKey_Search(bBlocked)
    t.set("setBlockMainKey_Search", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            ((LoveAndroid) vm.getActivity()).setBlockMainKey_Search(args.checkboolean(1));
            return LuaValue.NONE;
        }
    });
    // / love.phone.setHapticFeedbackEnabled(bEnabled)
    t.set("setHapticFeedbackEnabled", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.getView().setHapticFeedbackEnabled(args.checkboolean(1));
            return LuaValue.NONE;
        }
    });
    // / love.phone.performHapticFeedback(feedbackConstant)
    // / see also FEEDBACK_CONSTANT
    t.set("performHapticFeedback", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.getView().performHapticFeedback(args.checkint(1));
            return LuaValue.NONE;
        }
    });
    // / love.phone.setKeepScreenOn(bool bKeepScreenOn)
    t.set("setKeepScreenOn", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.setKeepScreenOn(args.checkboolean(1));
            return LuaValue.NONE;
        }
    });
    // / love.phone.setRequestedOrientation(requestedOrientation)
    // / string param : behind,full_sensor,landscape,nosensor,portrait,reverse_landscape,reverse_portrait,sensor,sensor_landscape,sensor_portrait,unspecified,user
    // / for param meaning see also http://developer.android.com/reference/android/content/pm/ActivityInfo.html
    // / numeric parameter are still supported but are discouraged, see SCREEN_ORIENTATION
    t.set("setRequestedOrientation", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.getActivity().setRequestedOrientation(args.isstring(1) ? Str2ScreenOrientation(args.checkjstring(1)) : args.checkint(1));
            return LuaValue.NONE;
        }
    });
    // / love.phone.SCREEN_ORIENTATION = {[name]=value,...}
    // / see also http://developer.android.com/reference/android/content/pm/ActivityInfo.html
    {
        LuaTable c = new LuaTable();
        t.set("SCREEN_ORIENTATION", c);
        // /< 	Constant corresponding to behind in the screenOrientation attribute.
        c.set("SCREEN_ORIENTATION_BEHIND", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND);
        // ~ c.set("SCREEN_ORIENTATION_FULL_SENSOR",			android.content.pm.ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR	); ///< 	Constant corresponding to fullSensor in the screenOrientation attribute.
        // /< 	Constant corresponding to landscape in the screenOrientation attribute.
        c.set("SCREEN_ORIENTATION_LANDSCAPE", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        // /< 	Constant corresponding to nosensor in the screenOrientation attribute.
        c.set("SCREEN_ORIENTATION_NOSENSOR", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
        // /< 	Constant corresponding to portrait in the screenOrientation attribute.
        c.set("SCREEN_ORIENTATION_PORTRAIT", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        // ~ c.set("SCREEN_ORIENTATION_REVERSE_LANDSCAPE",	android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE	); ///< 	Constant corresponding to reverseLandscape in the screenOrientation attribute.
        // ~ c.set("SCREEN_ORIENTATION_REVERSE_PORTRAIT",	android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT	); ///< 	Constant corresponding to reversePortrait in the screenOrientation attribute.
        // /< 	Constant corresponding to sensor in the screenOrientation attribute.
        c.set("SCREEN_ORIENTATION_SENSOR", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR);
        // ~ c.set("SCREEN_ORIENTATION_SENSOR_LANDSCAPE",	android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE	); ///< 	Constant corresponding to sensorLandscape in the screenOrientation attribute.
        // ~ c.set("SCREEN_ORIENTATION_SENSOR_PORTRAIT",		android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT	); ///< 	Constant corresponding to sensorPortrait in the screenOrientation attribute.
        // /< 	Constant corresponding to unspecified in the screenOrientation attribute.
        c.set("SCREEN_ORIENTATION_UNSPECIFIED", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
        // /< 	Constant corresponding to user in the screenOrientation attribute.
        c.set("SCREEN_ORIENTATION_USER", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER);
    }
    // / love.phone.FEEDBACK_CONSTANT = {[name]=value,...}
    // / see also http://developer.android.com/reference/android/view/HapticFeedbackConstants.html
    {
        LuaTable c = new LuaTable();
        t.set("FEEDBACK_CONSTANT", c);
        // /< Flag for View.performHapticFeedback(int, int): Ignore the global setting for whether to perform haptic feedback, do it always.
        c.set("FLAG_IGNORE_GLOBAL_SETTING", android.view.HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
        // /< Flag for View.performHapticFeedback(int, int): Ignore the setting in the view for whether to perform haptic feedback, do it always.
        c.set("FLAG_IGNORE_VIEW_SETTING", android.view.HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
        // ~ c.set("KEYBOARD_TAP",				android.view.HapticFeedbackConstants.KEYBOARD_TAP 					); ///< The user has pressed a soft keyboard key.	// FIXME: cannot be resolved or is not a field
        // /< The user has performed a long press on an object that is resulting in an action being performed.
        c.set("LONG_PRESS", android.view.HapticFeedbackConstants.LONG_PRESS);
        // /< The user has pressed on a virtual on-screen key.
        c.set("VIRTUAL_KEY", android.view.HapticFeedbackConstants.VIRTUAL_KEY);
    }
    // / love.phone.SENSOR_TYPE = {[name]=value,...}
    // / see also http://developer.android.com/reference/android/hardware/Sensor.html
    // / see also http://developer.android.com/reference/android/hardware/SensorEvent.html#values
    {
        LuaTable c = new LuaTable();
        t.set("SENSOR_TYPE", c);
        c.set("TYPE_ACCELEROMETER", Sensor.TYPE_ACCELEROMETER);
        c.set("TYPE_ALL", Sensor.TYPE_ALL);
        // ~ c.set(	"TYPE_AMBIENT_TEMPERATURE",		Sensor.TYPE_AMBIENT_TEMPERATURE	); // FIXME: cannot be resolved or is not a field
        // ~ c.set(	"TYPE_GRAVITY",					Sensor.TYPE_GRAVITY				); // FIXME: cannot be resolved or is not a field
        c.set("TYPE_GYROSCOPE", Sensor.TYPE_GYROSCOPE);
        c.set("TYPE_LIGHT", Sensor.TYPE_LIGHT);
        // ~ c.set(	"TYPE_LINEAR_ACCELERATION",		Sensor.TYPE_LINEAR_ACCELERATION	); // FIXME: cannot be resolved or is not a field
        // compass
        c.set("TYPE_MAGNETIC_FIELD", Sensor.TYPE_MAGNETIC_FIELD);
        c.set("TYPE_ORIENTATION", Sensor.TYPE_ORIENTATION);
        c.set("TYPE_PRESSURE", Sensor.TYPE_PRESSURE);
        c.set("TYPE_PROXIMITY", Sensor.TYPE_PROXIMITY);
    // ~ c.set(	"TYPE_RELATIVE_HUMIDITY",		Sensor.TYPE_RELATIVE_HUMIDITY	); // FIXME: cannot be resolved or is not a field
    // ~ c.set(	"TYPE_ROTATION_VECTOR",			Sensor.TYPE_ROTATION_VECTOR		); // FIXME: cannot be resolved or is not a field
    }
    // / love.phone.MOTION_EVENT_ACTION_TYPE = {[name]=value,...}
    // / e.g. love.phone.touch(..) event
    // / see also http://developer.android.com/reference/android/view/MotionEvent.html
    {
        LuaTable c = new LuaTable();
        t.set("MOTION_EVENT_ACTION_TYPE", c);
        c.set("ACTION_CANCEL", MotionEvent.ACTION_CANCEL);
        c.set("ACTION_DOWN", MotionEvent.ACTION_DOWN);
        c.set("ACTION_MASK", MotionEvent.ACTION_MASK);
        c.set("ACTION_MOVE", MotionEvent.ACTION_MOVE);
        c.set("ACTION_OUTSIDE", MotionEvent.ACTION_OUTSIDE);
        c.set("ACTION_POINTER_1_DOWN", MotionEvent.ACTION_POINTER_1_DOWN);
        c.set("ACTION_POINTER_1_UP", MotionEvent.ACTION_POINTER_1_UP);
        c.set("ACTION_POINTER_2_DOWN", MotionEvent.ACTION_POINTER_2_DOWN);
        c.set("ACTION_POINTER_2_UP", MotionEvent.ACTION_POINTER_2_UP);
        c.set("ACTION_POINTER_3_DOWN", MotionEvent.ACTION_POINTER_3_DOWN);
        c.set("ACTION_POINTER_3_UP", MotionEvent.ACTION_POINTER_3_UP);
        c.set("ACTION_POINTER_DOWN", MotionEvent.ACTION_POINTER_DOWN);
        c.set("ACTION_POINTER_ID_MASK", MotionEvent.ACTION_POINTER_ID_MASK);
        c.set("ACTION_POINTER_ID_SHIFT", MotionEvent.ACTION_POINTER_ID_SHIFT);
        c.set("ACTION_POINTER_UP", MotionEvent.ACTION_POINTER_UP);
        c.set("ACTION_UP", MotionEvent.ACTION_UP);
    }
    return t;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) Varargs(org.luaj.vm2.Varargs) List(java.util.List) LuaValue(org.luaj.vm2.LuaValue) VarArgFunction(org.luaj.vm2.lib.VarArgFunction) LuanObjImage(net.schattenkind.androidLove.luan.obj.LuanObjImage) Sensor(android.hardware.Sensor)

Example 14 with LuaValue

use of org.luaj.vm2.LuaValue 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 15 with LuaValue

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

the class LuanPhysics method InitLib.

public LuaTable InitLib() {
    LuaTable t = LuaValue.tableOf();
    LuaValue _G = vm.get_G();
    _G.set(sMetaName_World, LuanObjWorld.CreateMetaTable(this));
    _G.set(sMetaName_Body, LuanObjBody.CreateMetaTable(this));
    _G.set(sMetaName_Shape, LuanObjShape.CreateMetaTable(this));
    _G.set(sMetaName_CircleShape, LuanObjCircleShape.CreateMetaTable(this));
    _G.set(sMetaName_PolygonShape, LuanObjPolygonShape.CreateMetaTable(this));
    _G.set(sMetaName_Contact, LuanObjContact.CreateMetaTable(this));
    _G.set(sMetaName_Joint, LuanObjJoint.CreateMetaTable(this));
    t.set("newWorld", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.userdataOf(new LuanObjWorld(LuanPhysics.this), vm.get_G().get(sMetaName_World));
        }
    });
    t.set("newBody", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.userdataOf(new LuanObjBody(LuanPhysics.this), vm.get_G().get(sMetaName_Body));
        }
    });
    t.set("newRectangleShape", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.userdataOf(new LuanObjPolygonShape(LuanPhysics.this), vm.get_G().get(sMetaName_PolygonShape));
        }
    });
    t.set("newCircleShape", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.userdataOf(new LuanObjCircleShape(LuanPhysics.this), vm.get_G().get(sMetaName_CircleShape));
        }
    });
    t.set("newPolygonShape", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.userdataOf(new LuanObjPolygonShape(LuanPhysics.this), vm.get_G().get(sMetaName_PolygonShape));
        }
    });
    t.set("newDistanceJoint", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.userdataOf(new LuanObjJoint(LuanPhysics.this), vm.get_G().get(sMetaName_Joint));
        }
    });
    t.set("newGearJoint", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.userdataOf(new LuanObjJoint(LuanPhysics.this), vm.get_G().get(sMetaName_Joint));
        }
    });
    t.set("newMouseJoint", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.userdataOf(new LuanObjJoint(LuanPhysics.this), vm.get_G().get(sMetaName_Joint));
        }
    });
    t.set("newPrismaticJoint", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.userdataOf(new LuanObjJoint(LuanPhysics.this), vm.get_G().get(sMetaName_Joint));
        }
    });
    t.set("newPulleyJoint", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.userdataOf(new LuanObjJoint(LuanPhysics.this), vm.get_G().get(sMetaName_Joint));
        }
    });
    t.set("newRevoluteJoint", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.userdataOf(new LuanObjJoint(LuanPhysics.this), vm.get_G().get(sMetaName_Joint));
        }
    });
    return t;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) Varargs(org.luaj.vm2.Varargs) LuaValue(org.luaj.vm2.LuaValue) VarArgFunction(org.luaj.vm2.lib.VarArgFunction)

Aggregations

LuaValue (org.luaj.vm2.LuaValue)55 LuaTable (org.luaj.vm2.LuaTable)37 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)6 LuaError (org.luaj.vm2.LuaError)6 LuaFunction (org.luaj.vm2.LuaFunction)6 View (android.view.View)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 LuaViewApi (com.taobao.luaview.fun.mapper.LuaViewApi)2 UDLuaTable (com.taobao.luaview.userdata.base.UDLuaTable)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2