Fixed varargs invocation from luajava
This commit is contained in:
@@ -52,7 +52,7 @@ class JavaMember extends VarArgFunction {
|
|||||||
fixedargs = new CoerceLuaToJava.Coercion[isvarargs? params.length-1: params.length];
|
fixedargs = new CoerceLuaToJava.Coercion[isvarargs? params.length-1: params.length];
|
||||||
for ( int i=0; i<fixedargs.length; i++ )
|
for ( int i=0; i<fixedargs.length; i++ )
|
||||||
fixedargs[i] = CoerceLuaToJava.getCoercion( params[i] );
|
fixedargs[i] = CoerceLuaToJava.getCoercion( params[i] );
|
||||||
varargs = isvarargs? CoerceLuaToJava.getCoercion( params[params.length-1] ): null;
|
varargs = isvarargs? CoerceLuaToJava.getCoercion( params[params.length-1].getComponentType() ): null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int score(Varargs args) {
|
int score(Varargs args) {
|
||||||
@@ -73,17 +73,15 @@ class JavaMember extends VarArgFunction {
|
|||||||
for ( int i=0; i<a.length; i++ )
|
for ( int i=0; i<a.length; i++ )
|
||||||
a[i] = fixedargs[i].coerce( args.arg(i+1) );
|
a[i] = fixedargs[i].coerce( args.arg(i+1) );
|
||||||
} else {
|
} else {
|
||||||
int n = Math.max(fixedargs.length,args.narg());
|
// should be the fixed arguments, followed by an array with the varargs
|
||||||
// This situation indicates that the method has only one input parameter,
|
a = new Object[fixedargs.length+1];
|
||||||
// and the parameter is a variable parameter type, etc: append(String...args).
|
int nvar = Math.max(0, args.narg()-fixedargs.length);
|
||||||
if (n == 0 && varargs instanceof CoerceLuaToJava.ArrayCoercion) {
|
Object[] vararray = new Object[nvar];
|
||||||
return new Object[] {Array.newInstance(((CoerceLuaToJava.ArrayCoercion)varargs).componentType,0)};
|
|
||||||
}
|
|
||||||
a = new Object[n];
|
|
||||||
for ( int i=0; i<fixedargs.length; i++ )
|
for ( int i=0; i<fixedargs.length; i++ )
|
||||||
a[i] = fixedargs[i].coerce( args.arg(i+1) );
|
a[i] = fixedargs[i].coerce( args.arg(i+1) );
|
||||||
for ( int i=fixedargs.length; i<n; i++ )
|
a[a.length-1] = vararray;
|
||||||
a[i] = varargs.coerce( args.arg(i+1) );
|
for ( int i=0; i<nvar; i++ )
|
||||||
|
vararray[i] = varargs.coerce( args.arg(fixedargs.length+i+1) );
|
||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user