Allow calling methods with float arguments with LuaJava.
This commit is contained in:
@@ -119,6 +119,18 @@ public class CoerceLuaToJava {
|
|||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Coercion floatCoercion = new Coercion() {
|
||||||
|
public Object coerce(LValue value) {
|
||||||
|
return new Float( value.toJavaFloat() );
|
||||||
|
}
|
||||||
|
public int score( LValue value ) {
|
||||||
|
if ( value instanceof LNumber )
|
||||||
|
return 1;
|
||||||
|
if ( value instanceof LBoolean )
|
||||||
|
return 2;
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
};
|
||||||
Coercion doubleCoercion = new Coercion() {
|
Coercion doubleCoercion = new Coercion() {
|
||||||
public Object coerce(LValue value) {
|
public Object coerce(LValue value) {
|
||||||
return new Double( value.toJavaDouble() );
|
return new Double( value.toJavaDouble() );
|
||||||
@@ -177,6 +189,8 @@ public class CoerceLuaToJava {
|
|||||||
COERCIONS.put( Integer.class, intCoercion );
|
COERCIONS.put( Integer.class, intCoercion );
|
||||||
COERCIONS.put( Long.TYPE, longCoercion );
|
COERCIONS.put( Long.TYPE, longCoercion );
|
||||||
COERCIONS.put( Long.class, longCoercion );
|
COERCIONS.put( Long.class, longCoercion );
|
||||||
|
COERCIONS.put( Float.TYPE, floatCoercion );
|
||||||
|
COERCIONS.put( Float.class, floatCoercion );
|
||||||
COERCIONS.put( Double.TYPE, doubleCoercion );
|
COERCIONS.put( Double.TYPE, doubleCoercion );
|
||||||
COERCIONS.put( Double.class, doubleCoercion );
|
COERCIONS.put( Double.class, doubleCoercion );
|
||||||
COERCIONS.put( String.class, stringCoercion );
|
COERCIONS.put( String.class, stringCoercion );
|
||||||
|
|||||||
5
src/test/res/testfloat.lua
Normal file
5
src/test/res/testfloat.lua
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
local f = luajava.bindClass("java.lang.Float")
|
||||||
|
print(f:toHexString(0.5))
|
||||||
|
print(f:valueOf(0.5))
|
||||||
|
print(f:valueOf("0.5"))
|
||||||
|
|
||||||
Reference in New Issue
Block a user