fixed bug: invoke overload method disorder
This commit is contained in:
@@ -1,24 +1,24 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2011 Luaj.org. All rights reserved.
|
* Copyright (c) 2011 Luaj.org. All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.luaj.vm2.libs.jse;
|
package org.luaj.vm2.libs.jse;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@@ -114,8 +114,19 @@ class JavaMethod extends JavaMember {
|
|||||||
|
|
||||||
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,6 +151,10 @@ 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 n = args.narg();
|
||||||
|
if (n == 0 && noArgMethodIndex != -1) {
|
||||||
|
best = methods[noArgMethodIndex];
|
||||||
|
} else {
|
||||||
int score = CoerceLuaToJava.SCORE_UNCOERCIBLE;
|
int score = CoerceLuaToJava.SCORE_UNCOERCIBLE;
|
||||||
for ( int i=0; i<methods.length; i++ ) {
|
for ( int i=0; i<methods.length; i++ ) {
|
||||||
int s = methods[i].score(args);
|
int s = methods[i].score(args);
|
||||||
@@ -150,6 +165,7 @@ class JavaMethod extends JavaMember {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// any match?
|
// any match?
|
||||||
if ( best == null )
|
if ( best == null )
|
||||||
|
|||||||
Reference in New Issue
Block a user