Fix selection logic in luajava when picking from functions with same name
This commit is contained in:
@@ -722,7 +722,8 @@ and LuaForge:
|
||||
<li>JSR-223 fixes: add META-INF/services entry in jse jar, improve bindings implementation
|
||||
</ul></td></tr>
|
||||
<tr valign="top"><td> <b>2.0.2</b></td><td><ul>
|
||||
<li>JSR-223 bindings will pass values that are not primitives as LuaValue
|
||||
<li>JSR-223 bindings change: non Java-primitives will now be passed as LuaValue
|
||||
<li>Fix selection logic when picking from functions with same name
|
||||
</ul></td></tr>
|
||||
</table>
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user