Allow calling methods with float arguments with LuaJava.

This commit is contained in:
Ian Farmer
2009-01-04 01:15:19 +00:00
parent 198a19c861
commit 69a438e0d4
2 changed files with 19 additions and 0 deletions

View File

@@ -119,6 +119,18 @@ public class CoerceLuaToJava {
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() {
public Object coerce(LValue value) {
return new Double( value.toJavaDouble() );
@@ -177,6 +189,8 @@ public class CoerceLuaToJava {
COERCIONS.put( Integer.class, intCoercion );
COERCIONS.put( Long.TYPE, longCoercion );
COERCIONS.put( Long.class, longCoercion );
COERCIONS.put( Float.TYPE, floatCoercion );
COERCIONS.put( Float.class, floatCoercion );
COERCIONS.put( Double.TYPE, doubleCoercion );
COERCIONS.put( Double.class, doubleCoercion );
COERCIONS.put( String.class, stringCoercion );

View 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"))