fix bug: invoke overload method disorder #104

Closed
uyong wants to merge 1 commits from uyong/fix-overload-method-bug into master

View File

@@ -113,9 +113,20 @@ class JavaMethod extends JavaMember {
static class Overload extends LuaFunction { static class Overload extends LuaFunction {
final JavaMethod[] methods; final JavaMethod[] methods;
// no parammeter method index in overload method
int noArgMethodIndex = -1;
Overload(JavaMethod[] methods) { Overload(JavaMethod[] methods) {
this.methods = methods; this.methods = methods;
JavaMethod m;
for (int i=0; i<methods.length; i++) {
m = methods[i];
if (m.fixedargs.length == 0 && m.varargs == null) {
noArgMethodIndex = i;
break;
}
}
} }
public LuaValue call() { public LuaValue call() {
@@ -140,14 +151,19 @@ class JavaMethod extends JavaMember {
private LuaValue invokeBestMethod(Object instance, Varargs args) { private LuaValue invokeBestMethod(Object instance, Varargs args) {
JavaMethod best = null; JavaMethod best = null;
int score = CoerceLuaToJava.SCORE_UNCOERCIBLE; int n = args.narg();
for ( int i=0; i<methods.length; i++ ) { if (n == 0 && noArgMethodIndex != -1) {
int s = methods[i].score(args); best = methods[noArgMethodIndex];
if ( s < score ) { } else {
score = s; int score = CoerceLuaToJava.SCORE_UNCOERCIBLE;
best = methods[i]; for ( int i=0; i<methods.length; i++ ) {
if ( score == 0 ) int s = methods[i].score(args);
break; if ( s < score ) {
score = s;
best = methods[i];
if ( score == 0 )
break;
}
} }
} }