use of org.luaj.vm2.LuaTable in project love-android by hagish.
the class LuanObjImage method CreateMetaTable.
public static LuaTable CreateMetaTable(final LuanGraphics g) {
LuaTable mt = LuaValue.tableOf();
LuaTable t = LuaValue.tableOf();
mt.set("__index", t);
/// min, mag = Image:getFilter( ) "linear" , "nearest"
t.set("getFilter", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.varargsOf(LuaValue.valueOf(Filter2Str(self(args).mFilterMin)), LuaValue.valueOf(Filter2Str(self(args).mFilterMag)));
}
});
/// Image:setFilter( min, mag ) "linear" , "nearest"
t.set("setFilter", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).setFilter(Str2Filter(args.checkjstring(2)), Str2Filter(args.checkjstring(3)));
return LuaValue.NONE;
}
});
/// horiz, vert = Image:getWrap( ) "repeat" , "clamp"
t.set("getWrap", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.varargsOf(LuaValue.valueOf(Wrap2Str(self(args).mWrapH)), LuaValue.valueOf(Wrap2Str(self(args).mWrapV)));
}
});
/// Image:setWrap( horiz, vert ) "repeat" , "clamp"
t.set("setWrap", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).setWrap(Str2Wrap(args.checkjstring(2)), Str2Wrap(args.checkjstring(3)));
return LuaValue.NONE;
}
});
/// w = Image:getWidth( )
t.set("getWidth", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf(self(args).mWidth);
}
});
/// h = Image:getHeight( )
t.set("getHeight", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf(self(args).mHeight);
}
});
/// type = Object:type() , e.g. "Image" or audio:"Source"
t.set("type", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf("Image");
}
});
/// 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("Drawable") || s.equals("Image"));
}
});
return mt;
}
use of org.luaj.vm2.LuaTable in project love-android by hagish.
the class LuanObjParticleSystem method CreateMetaTable.
public static LuaTable CreateMetaTable(final LuanGraphics g) {
LuaTable mt = LuaValue.tableOf();
LuaTable t = LuaValue.tableOf();
mt.set("__index", t);
// TODO: not yet implemented
t.set("setSpinVariation", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
g.vm.NotImplemented("ParticleSystem:" + "setSpinVariation");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("setSizeVariation", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
g.vm.NotImplemented("ParticleSystem:" + "setSizeVariation");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("setBufferSize", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
g.vm.NotImplemented("ParticleSystem:" + "setBufferSize");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("setSprite", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
g.vm.NotImplemented("ParticleSystem:" + "setSprite");
return LuaValue.NONE;
}
});
// TODO: not yet implemented
t.set("count", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf(self(args).miParticlesAlive);
}
});
t.set("getDirection", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf(self(args).fDirection);
}
});
t.set("getOffsetX", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf(self(args).fOX);
}
});
t.set("getOffsetY", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf(self(args).fOY);
}
});
t.set("getSpread", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf(self(args).fSpread);
}
});
t.set("isActive", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf(self(args).bEmitterActive);
}
});
t.set("isEmpty", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf(self(args).miParticlesAlive == 0);
}
});
t.set("isFull", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf(self(args).miParticlesAlive >= self(args).iMaxParticles);
}
});
t.set("setOffset", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).fOX = (float) args.checkdouble(2);
self(args).fOY = (float) args.checkdouble(3);
return LuaValue.NONE;
}
});
t.set("setColor", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).col_start = new LuanColor(args, 2);
self(args).col_end = new LuanColor(args, 6);
return LuaValue.NONE;
}
});
t.set("setGravity", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).fGravityX = (float) args.checkdouble(2);
self(args).fGravityY = LuanBase.IsArgSet(args, 3) ? (float) args.checkdouble(3) : self(args).fGravityX;
return LuaValue.NONE;
}
});
t.set("setRotation", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).fRotationMin = (float) args.checkdouble(2);
self(args).fRotationMax = LuanBase.IsArgSet(args, 3) ? (float) args.checkdouble(3) : self(args).fRotationMin;
return LuaValue.NONE;
}
});
t.set("setSpin", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).fSpinStart = (float) args.checkdouble(2);
self(args).fSpinEnd = LuanBase.IsArgSet(args, 3) ? (float) args.checkdouble(3) : self(args).fSpinStart;
self(args).fSpinVar = LuanBase.IsArgSet(args, 4) ? (float) args.checkdouble(4) : 1f;
return LuaValue.NONE;
}
});
t.set("setRadialAcceleration", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).fRadialAccelerationMin = (float) args.checkdouble(2);
self(args).fRadialAccelerationMax = LuanBase.IsArgSet(args, 3) ? (float) args.checkdouble(3) : self(args).fRadialAccelerationMin;
return LuaValue.NONE;
}
});
t.set("setTangentialAcceleration", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).fTangentialAccelerationMin = (float) args.checkdouble(2);
self(args).fTangentialAccelerationMax = LuanBase.IsArgSet(args, 3) ? (float) args.checkdouble(3) : self(args).fTangentialAccelerationMin;
return LuaValue.NONE;
}
});
t.set("setDirection", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).fDirection = (float) args.checkdouble(2);
return LuaValue.NONE;
}
});
t.set("setSpread", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).fSpread = (float) args.checkdouble(2);
return LuaValue.NONE;
}
});
t.set("setSpeed", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).fSpeed_Min = (float) args.checkdouble(2);
self(args).fSpeed_Max = LuanBase.IsArgSet(args, 3) ? (float) args.checkdouble(3) : self(args).fSpeed_Min;
return LuaValue.NONE;
}
});
t.set("setEmissionRate", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).setEmissionRate((float) args.checkdouble(2));
return LuaValue.NONE;
}
});
t.set("setParticleLife", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
float fMin = (float) args.checkdouble(2);
float fMax = LuanBase.IsArgSet(args, 3) ? (float) args.checkdouble(3) : fMin;
self(args).setParticleLife(fMin, fMax);
return LuaValue.NONE;
}
});
t.set("setSize", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
float fStart = (float) args.checkdouble(2);
float fEnd = LuanBase.IsArgSet(args, 3) ? (float) args.checkdouble(3) : fStart;
float fVar = LuanBase.IsArgSet(args, 4) ? (float) args.checkdouble(4) : 1f;
self(args).setSize(fStart, fEnd, fVar);
return LuaValue.NONE;
}
});
t.set("setLifetime", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).setLifetime((float) args.checkdouble(2));
return LuaValue.NONE;
}
});
t.set("setPosition", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).setPosition((float) args.checkdouble(2), (float) args.checkdouble(3));
return LuaValue.NONE;
}
});
t.set("getX", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf(self(args).x_emit);
}
});
t.set("getY", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf(self(args).y_emit);
}
});
t.set("pause", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).pause();
return LuaValue.NONE;
}
});
t.set("reset", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).reset();
return LuaValue.NONE;
}
});
t.set("start", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).start();
return LuaValue.NONE;
}
});
t.set("stop", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).stop();
return LuaValue.NONE;
}
});
/// ParticleSystem:update( dt )
/// Updates the particle system; moving, creating and killing particles.
// TODO: not yet implemented
t.set("update", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).update((float) args.checkdouble(2));
return LuaValue.NONE;
}
});
/// 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("Drawable") || s.equals("ParticleSystem"));
}
});
return mt;
}
use of org.luaj.vm2.LuaTable in project love-android by hagish.
the class LuanObjQuad method CreateMetaTable.
public static LuaTable CreateMetaTable(final LuanGraphics g) {
LuaTable mt = LuaValue.tableOf();
LuaTable t = LuaValue.tableOf();
mt.set("__index", t);
/// Quad:flip( x, y ) booleans which axis should be flipped
t.set("flip", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).flip(args.checkboolean(2), args.checkboolean(3));
return LuaValue.NONE;
}
});
/// x, y, w, h = Quad:getViewport( )
/// Gets the current viewport of this Quad.
/// @x The top-left corner along the x-axis.
/// @y The top-right corner along the y-axis.
/// @w The width of the viewport.
/// @h The height of the viewport.
t.set("getViewport", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
LuanObjQuad me = self(args);
return LuaValue.varargsOf(LuaValue.valueOf(me.x), LuaValue.valueOf(me.y), LuaValue.varargsOf(LuaValue.valueOf(me.w), LuaValue.valueOf(me.h)));
}
});
/// Quad:setViewport( x, y, w, h )
/// Sets the texture coordinates according to a viewport.
/// @x The top-left corner along the x-axis.
/// @y The top-right corner along the y-axis.
/// @w The width of the viewport.
/// @h The height of the viewport.
t.set("setViewport", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
self(args).setViewport((float) args.checkdouble(2), (float) args.checkdouble(3), (float) args.checkdouble(4), (float) args.checkdouble(5));
return LuaValue.NONE;
}
});
/// type = Object:type() , e.g. "Image" or audio:"Source"
t.set("type", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.valueOf("Quad");
}
});
/// 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("Quad"));
}
});
return mt;
}
use of org.luaj.vm2.LuaTable 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));
}
use of org.luaj.vm2.LuaTable 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;
}
Aggregations