Fix two bugs in LuaJava compatibility addon:
(1) LDouble to Double/double coercions were missing (2) LuaJava.LMethod.luaStackCall adjusted the top of stack in a way that produces the wrong results when the call occurs as the argument to another function (such as print) Also added two lines to the bottom of test7.lua to test luajava.bindClass.
This commit is contained in:
@@ -50,6 +50,20 @@ public class CoerceLuaToJava {
|
||||
return 4;
|
||||
}
|
||||
};
|
||||
Coercion doubleCoercion = new Coercion() {
|
||||
public Object coerce(LValue value) {
|
||||
return Double.valueOf( value.luaAsDouble() );
|
||||
}
|
||||
public int score(LValue value) {
|
||||
if ( value instanceof LDouble )
|
||||
return 0;
|
||||
if ( value instanceof LNumber )
|
||||
return 1;
|
||||
if ( value instanceof LBoolean || value == LNil.NIL )
|
||||
return 2;
|
||||
return 4;
|
||||
}
|
||||
};
|
||||
Coercion stringCoercion = new Coercion() {
|
||||
public Object coerce(LValue value) {
|
||||
return value.luaAsString();
|
||||
@@ -92,6 +106,8 @@ public class CoerceLuaToJava {
|
||||
COERCIONS.put( Integer.class, intCoercion );
|
||||
COERCIONS.put( Long.TYPE, intCoercion );
|
||||
COERCIONS.put( Long.class, intCoercion );
|
||||
COERCIONS.put( Double.TYPE, doubleCoercion );
|
||||
COERCIONS.put( Double.class, doubleCoercion );
|
||||
COERCIONS.put( String.class, stringCoercion );
|
||||
COERCIONS.put( Object.class, objectCoercion );
|
||||
}
|
||||
|
||||
@@ -173,7 +173,6 @@ public final class LuaJava extends LFunction {
|
||||
Object result = meth.invoke( instance, args );
|
||||
call.stack[base] = CoerceJavaToLua.coerce(result);
|
||||
call.top = base + 1;
|
||||
call.adjustTop(base+nresults);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -9,3 +9,6 @@ print( obj:getS() )
|
||||
|
||||
obj:setS( "World" )
|
||||
print( obj.s )
|
||||
|
||||
math = luajava.bindClass("java.lang.Math")
|
||||
print("Square root of 9 is", math:sqrt(9.0))
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user