diff --git a/src/j2se/org/luaj/lib/j2se/CoerceLuaToJava.java b/src/j2se/org/luaj/lib/j2se/CoerceLuaToJava.java index fe709c59..1610dddd 100644 --- a/src/j2se/org/luaj/lib/j2se/CoerceLuaToJava.java +++ b/src/j2se/org/luaj/lib/j2se/CoerceLuaToJava.java @@ -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 ); diff --git a/src/test/res/testfloat.lua b/src/test/res/testfloat.lua new file mode 100644 index 00000000..230864df --- /dev/null +++ b/src/test/res/testfloat.lua @@ -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")) +