use of org.luaj.vm2.lib.VarArgFunction in project love-android by hagish.
the class LuanKeyboard method InitLib.
public LuaTable InitLib() {
LuaTable t = LuaValue.tableOf();
// delay, interval = love.keyboard.getKeyRepeat( )
t.set("getKeyRepeat", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.varargsOf(LuaNumber.valueOf(repeatDelay), LuaNumber.valueOf(repeatInterval));
}
});
// down = love.keyboard.isDown( key )
t.set("isDown", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaBoolean.valueOf(isDown(args.arg1().toString()));
}
});
// love.keyboard.setKeyRepeat( delay, interval )
t.set("setKeyRepeat", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
repeatDelay = args.arg(1).tofloat();
repeatInterval = args.arg(2).tofloat();
return LuaValue.NONE;
}
});
return t;
}
use of org.luaj.vm2.lib.VarArgFunction in project love-android by hagish.
the class LuanMouse method InitLib.
public LuaTable InitLib() {
LuaTable t = LuaValue.tableOf();
// x, y = love.mouse.getPosition( )
t.set("getPosition", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.varargsOf(LuaNumber.valueOf(mouseX_for_vm()), LuaNumber.valueOf(mouseY_for_vm()));
}
});
// x = love.mouse.getX( )
t.set("getX", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaNumber.valueOf(mouseX_for_vm());
}
});
// y = love.mouse.getY( )
t.set("getY", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaNumber.valueOf(mouseY_for_vm());
}
});
// down = love.mouse.isDown( button )
t.set("isDown", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
String button = args.arg1().toString();
if (button.equals(LEFT_BUTTON)) {
return LuaBoolean.valueOf(mouseButtonLeft);
} else if (button.equals(MIDDLE_BUTTON)) {
return LuaBoolean.valueOf(mouseButtonMiddle);
} else if (button.equals(RIGHT_BUTTON)) {
return LuaBoolean.valueOf(mouseButtonRight);
}
return LuaValue.FALSE;
}
});
// grabbed = love.mouse.isGrabbed( )
t.set("isGrabbed", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.FALSE;
}
});
// visible = love.mouse.isVisible( )
t.set("isVisible", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.FALSE;
}
});
// love.mouse.setGrab( grab )
t.set("setGrab", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.NONE;
}
});
// love.mouse.setPosition( x, y )
t.set("setPosition", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
mouseX = args.arg(1).toint();
mouseY = args.arg(2).toint();
return LuaValue.NONE;
}
});
// love.mouse.setVisible( visible )
t.set("setVisible", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
return LuaValue.NONE;
}
});
return t;
}
use of org.luaj.vm2.lib.VarArgFunction 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;
}
use of org.luaj.vm2.lib.VarArgFunction 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;
}
use of org.luaj.vm2.lib.VarArgFunction in project love-android by hagish.
the class LuanThread method InitLib.
public LuaTable InitLib() {
LuaTable t = LuaValue.tableOf();
LuaValue _G = vm.get_G();
_G.set(sMetaName_LuanThread, LuanObjThreadObj.CreateMetaTable(this));
/// thread = love.thread.newThread( name, filename )
/// thread = love.thread.newThread( name, file ) -- File file : The file to use as source.
/// thread = love.thread.newThread( name, data ) -- Data data : The data to use as source.
/// Creates a new Thread from a File or Data Object.
t.set("newThread", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
String name = args.checkjstring(1);
// TODO: param2 ? can be different things
try {
return LuaValue.userdataOf(new LuanObjThreadObj(LuanThread.this, name), vm.get_G().get(sMetaName_LuanThread));
} catch (Exception e) {
vm.handleError(e);
}
return LuaValue.NONE;
}
});
/// thread = love.thread.getThread( name )
/// Look for a thread and get its object.
/// TODO: not yet implemented
t.set("getThread", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.thread.getThread");
return LuaValue.NONE;
}
});
/// threads = love.thread.getThreads( )
/// Get all threads.
/// TODO: not yet implemented
t.set("getThreads", new VarArgFunction() {
@Override
public Varargs invoke(Varargs args) {
vm.NotImplemented("love.thread.getThreads");
return LuaValue.NONE;
}
});
return t;
}
Aggregations