Search in sources :

Example 6 with VarArgFunction

use of org.luaj.vm2.lib.VarArgFunction 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 7 with VarArgFunction

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

the class LuanEvent method InitLib.

public LuaTable InitLib() {
    LuaTable t = LuaValue.tableOf();
    /// love.event.clear() 
    /// Clears the event queue. 
    /// TODO: not yet implemented
    t.set("clear", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.event.clear");
            return LuaValue.NONE;
        }
    });
    /// i = love.event.poll( )
    /// Gets an iterator for messages in the event queue. 
    /// TODO: not yet implemented
    t.set("poll", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.event.poll");
            return LuaValue.NONE;
        }
    });
    /// love.event.pump( )
    /// Pump events into the event queue. This is a low-level function, and is usually not called explicitly, but implicitly by love.event.poll() or love.event.wait(). 
    /// TODO: not yet implemented
    t.set("pump", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.event.pump");
            return LuaValue.NONE;
        }
    });
    /// love.event.clear()
    /// TODO: not yet implemented
    t.set("clear", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.event.clear");
            return LuaValue.NONE;
        }
    });
    /// love.event.push( e, a, b, c )
    /// Adds an event to the event queue. 
    /// TODO: not yet implemented
    t.set("push", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            // special: param1=q -> quit
            String s = args.checkjstring(1);
            if (s.equals("q")) {
                vm.quitGame();
            }
            vm.NotImplemented("love.event.push");
            return LuaValue.NONE;
        }
    });
    /// e, a, b, c = love.event.wait( )
    /// Like love.event.poll(), but blocks until there is an event in the queue. 
    /// TODO: not yet implemented
    t.set("wait", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.event.wait");
            return LuaValue.NONE;
        }
    });
    return t;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) Varargs(org.luaj.vm2.Varargs) VarArgFunction(org.luaj.vm2.lib.VarArgFunction)

Example 8 with VarArgFunction

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

the class LuanJoystick method InitLib.

public LuaTable InitLib() {
    LuaTable t = LuaValue.tableOf();
    // TODO: not yet implemented
    t.set("close", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.joystick." + "close");
            return LuaValue.NONE;
        }
    });
    t.set("getAxes", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.joystick." + "getAxes");
            return LuaValue.varargsOf(LuaValue.ZERO, LuaValue.ZERO, LuaValue.ZERO);
        }
    });
    t.set("getAxis", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.joystick." + "getAxis");
            return LuaValue.ZERO;
        }
    });
    t.set("getBall", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.joystick." + "getBall");
            return LuaValue.varargsOf(LuaValue.ZERO, LuaValue.ZERO);
        }
    });
    t.set("getHat", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.joystick." + "getHat");
            return LuaValue.ZERO;
        }
    });
    t.set("getName", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.joystick." + "getName");
            return LuaValue.NONE;
        }
    });
    t.set("getNumAxes", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.joystick." + "getNumAxes");
            return LuaValue.ZERO;
        }
    });
    t.set("getNumBalls", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.joystick." + "getNumBalls");
            return LuaValue.ZERO;
        }
    });
    t.set("getNumButtons", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.joystick." + "getNumButtons");
            return LuaValue.ZERO;
        }
    });
    t.set("getNumHats", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.joystick." + "getNumHats");
            return LuaValue.ZERO;
        }
    });
    t.set("getNumJoysticks", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.joystick." + "getNumJoysticks");
            return LuaValue.ZERO;
        }
    });
    t.set("isDown", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.joystick." + "isDown");
            return LuaValue.NONE;
        }
    });
    t.set("isOpen", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.joystick." + "isOpen");
            return LuaValue.NONE;
        }
    });
    t.set("open", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.NotImplemented("love.joystick." + "open");
            return LuaValue.NONE;
        }
    });
    return t;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) Varargs(org.luaj.vm2.Varargs) VarArgFunction(org.luaj.vm2.lib.VarArgFunction)

Example 9 with VarArgFunction

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

the class LuanObjFont method CreateMetaTable.

public static LuaTable CreateMetaTable(final LuanGraphics g) {
    LuaTable mt = LuaValue.tableOf();
    LuaTable t = LuaValue.tableOf();
    mt.set("__index", t);
    /// height = Font:getHeight( )
    t.set("getHeight", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.valueOf(self(args).font_h);
        }
    });
    /// height = Font:getLineHeight( )
    t.set("getLineHeight", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.valueOf(self(args).line_h);
        }
    });
    /// width = Font:getWidth( line )
    t.set("getWidth", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.valueOf(self(args).getLineW(args.checkjstring(2)));
        }
    });
    /// Font:setLineHeight( height )
    t.set("setLineHeight", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            self(args).line_h = (float) args.checkdouble(2);
            return LuaValue.NONE;
        }
    });
    /// Font:getWrap(text, width)
    /// Returns how many lines text would be wrapped to. This function accounts for newlines correctly (i.e. '\n') 
    /// TODO:dummy
    t.set("getWrap", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            g.vm.NotImplemented("Font:getWrap");
            return LuaValue.valueOf(1);
        }
    });
    /// type = Object:type()  , e.g. "Image" or audio:"Source"
    t.set("type", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.valueOf("Font");
        }
    });
    /// b = Object:typeOf( name )
    t.set("typeOf", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            String s = args.checkjstring(2);
            return LuaValue.valueOf(s.equals("Object") || s.equals("Font"));
        }
    });
    return mt;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) Varargs(org.luaj.vm2.Varargs) VarArgFunction(org.luaj.vm2.lib.VarArgFunction)

Example 10 with VarArgFunction

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

the class LoveVM method setupCoreFunctions.

// ***** ***** ***** ***** ***** lua api
private void setupCoreFunctions() {
    _G.set("print", new VarArgFunction() {

        @Override
        public LuaValue invoke(Varargs args) {
            args.narg();
            StringBuffer s = new StringBuffer();
            for (int i = 1; i <= args.narg(); ++i) {
                if (i > 1) {
                    s.append(", ");
                }
                s.append(args.arg(i).toString());
            }
            LoveLog(TAG, s.toString());
            return LuaValue.NONE;
        }
    });
    _G.set("toast", new VarArgFunction() {

        @Override
        public LuaValue invoke(Varargs args) {
            args.narg();
            StringBuffer s = new StringBuffer();
            for (int i = 1; i <= args.narg(); ++i) {
                if (i > 1) {
                    s.append(", ");
                }
                s.append(args.arg(i).toString());
            }
            toast(s.toString());
            return LuaValue.NONE;
        }
    });
}
Also used : Varargs(org.luaj.vm2.Varargs) LuaValue(org.luaj.vm2.LuaValue) VarArgFunction(org.luaj.vm2.lib.VarArgFunction)

Aggregations

Varargs (org.luaj.vm2.Varargs)16 VarArgFunction (org.luaj.vm2.lib.VarArgFunction)16 LuaTable (org.luaj.vm2.LuaTable)15 LuaValue (org.luaj.vm2.LuaValue)7 List (java.util.List)2 LuanObjImage (net.schattenkind.androidLove.luan.obj.LuanObjImage)2 Sensor (android.hardware.Sensor)1 SoundPool (android.media.SoundPool)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 LuanColor (net.schattenkind.androidLove.luan.module.LuanRenderer.LuanColor)1 LuanObjFont (net.schattenkind.androidLove.luan.obj.LuanObjFont)1 LuanObjParticleSystem (net.schattenkind.androidLove.luan.obj.LuanObjParticleSystem)1 LuanObjQuad (net.schattenkind.androidLove.luan.obj.LuanObjQuad)1 Rectangle (net.schattenkind.androidLove.utils.Rectangle)1 LuaFunction (org.luaj.vm2.LuaFunction)1 LuaString (org.luaj.vm2.LuaString)1