Search in sources :

Example 16 with VarArgFunction

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

the class LuanTimer method InitLib.

public LuaTable InitLib() {
    LuaTable t = LuaValue.tableOf();
    // dt = love.timer.getDelta( )
    t.set("getDelta", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaNumber.valueOf(lastFrameDeltaInSec);
        }
    });
    // fps = love.timer.getFPS( )
    t.set("getFPS", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            float fps = 0.0f;
            if (lastFrameDeltaInSec > 0.0f) {
                fps = 1.0f / lastFrameDeltaInSec;
            }
            return LuaNumber.valueOf(fps);
        }
    });
    // t = love.timer.getMicroTime( )
    t.set("getMicroTime", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaNumber.valueOf(getTime());
        }
    });
    // time = love.timer.getTime( )
    t.set("getTime", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaNumber.valueOf(getTime());
        }
    });
    // love.timer.sleep( ms )
    t.set("sleep", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            try {
                Thread.sleep(args.arg1().toint(), 0);
            } catch (InterruptedException e) {
                LoveVM.LoveLogE(TAG, e.getMessage());
            }
            return LuaValue.NONE;
        }
    });
    // love.timer.step( )
    t.set("step", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            lastFrameStartInSec = getTime();
            return LuaValue.NONE;
        }
    });
    return t;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) Varargs(org.luaj.vm2.Varargs) 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