diff --git a/README.html b/README.html
index d137defc..5c3bfb15 100644
--- a/README.html
+++ b/README.html
@@ -722,7 +722,8 @@ and LuaForge:
JSR-223 fixes: add META-INF/services entry in jse jar, improve bindings implementation
| 2.0.2 |
-- JSR-223 bindings will pass values that are not primitives as LuaValue
+
- JSR-223 bindings change: non Java-primitives will now be passed as LuaValue
+
- Fix selection logic when picking from functions with same name
|
diff --git a/src/jse/org/luaj/vm2/lib/jse/CoerceLuaToJava.java b/src/jse/org/luaj/vm2/lib/jse/CoerceLuaToJava.java
index e5772c2c..04714b4a 100644
--- a/src/jse/org/luaj/vm2/lib/jse/CoerceLuaToJava.java
+++ b/src/jse/org/luaj/vm2/lib/jse/CoerceLuaToJava.java
@@ -174,10 +174,12 @@ public class CoerceLuaToJava {
}
public int score(int paramType) {
switch ( paramType ) {
- case LuaValue.TUSERDATA:
+ case LuaValue.TSTRING:
return 0;
- default:
+ case LuaValue.TUSERDATA:
return 1;
+ default:
+ return 2;
}
}
};
@@ -202,8 +204,10 @@ public class CoerceLuaToJava {
}
public int score(int paramType) {
switch ( paramType ) {
- case LuaValue.TSTRING:
+ case LuaValue.TUSERDATA:
return 0;
+ case LuaValue.TSTRING:
+ return 1;
default:
return 0x10;
}
@@ -238,7 +242,8 @@ public class CoerceLuaToJava {
if ( co != null ) {
int b = LuajavaLib.paramBaseTypeFromParamType(paramType);
int d = LuajavaLib.paramDepthFromParamType(paramType);
- return co.score( b ) * d;
+ int s = co.score(b);
+ return s * (d+1);
}
if ( c.isArray() ) {
Class typ = c.getComponentType();
diff --git a/test/junit/org/luaj/vm2/lib/jse/LuaJavaCoercionTest.java b/test/junit/org/luaj/vm2/lib/jse/LuaJavaCoercionTest.java
index 13e804f6..24f256fc 100644
--- a/test/junit/org/luaj/vm2/lib/jse/LuaJavaCoercionTest.java
+++ b/test/junit/org/luaj/vm2/lib/jse/LuaJavaCoercionTest.java
@@ -266,5 +266,31 @@ public class LuaJavaCoercionTest extends TestCase {
assertEquals( "12345678901234567890", sb );
assertEquals( "152415787532388367501905199875019052100", sc );
}
+
+ public static class A {
+ public String set( int foo ) {
+ return "from set(int) "+foo;
+ }
+ public String set( String foo ) {
+ return "from set(String) "+foo;
+ }
+ public String get() {
+ return "bar";
+ }
+ }
+
+ public void testOverloadedJavaMethods() {
+ String script =
+ "a = luajava.newInstance('"+A.class.getName()+"');\n" +
+ "return a:set(a:get())";
+ Varargs chunk = _G.get("loadstring").call(LuaValue.valueOf(script));
+ if ( ! chunk.arg1().toboolean() )
+ fail( chunk.arg(2).toString() );
+ Varargs results = chunk.arg1().invoke();
+ int nresults = results.narg();
+ String sa = results.tojstring(1);
+ assertEquals( 1, nresults );
+ assertEquals( "from set(String) bar", sa );
+ }
}