Hello everyone,
I am a new user and I have been doing some testing regarding Haxe and targeting various platforms.
I came across this bug with Reflect.callMethod when targeting Java/JVM, my code is as follow:
import haxe.Constraints.Function;
class Main {
static function main() {
var testing_Function:Function=function(arg1,arg2,arg3){trace(arg1,arg2,arg3);}
var arguments:Array=[“a”,“b”,“c”];
Reflect.callMethod(null,testing_Function,arguments);
}
}
If the number of arguments is only two, such as:
var arguments:Array=[“a”,“b”];
I get the expected result : a, b, null
If the number of arguments is more than two I get this error:
Exception in thread “main” java.lang.IllegalArgumentException
at haxe.jvm.Function.invokeDynamic(Unknown Source)
at haxe.jvm.Jvm.call(C:_\Haxe\HaxeToolkit\haxe\std/jvm/Jvm.hx:156)
at haxe.root.Reflect.callMethod(C:_\Haxe\HaxeToolkit\haxe\std/jvm/_std/Reflect.hx:78)
at haxe.root.Main.main(src/Main.hx:7)
at haxe.root.Main.main(src/Main.hx:1)
Error: Command failed with error 1
I am using Windows 11, VSCode and openjdk 21.0.6
I looked at the Haxe JVM class “Reflect” and method “callMethod”, as well as the class “Array” for args.getNative(), but could not find why it is limited to two arguments only:
haxe.root.Reflect.callMethod(C:_______\Haxe\HaxeToolkit\haxe\std/jvm/_std/Reflect.hx:78)
public static function callMethod(o:Dynamic, func:haxe.Constraints.Function, args:Array):Dynamic {
return Jvm.call(cast func, @:privateAccess args.getNative());
}
class Array
#if jvm
function getNative():NativeArray {
var a = new NativeArray(length);
System.arraycopy(__a, 0, a, 0, length);
return a;
}
#end
I did some research and found this article JVM Typed Functions - Haxe - The Cross-platform Toolkit where Reflect.callMethod is discussed at the end but I could not find any mention of argument limitation.
All other platforms I tested worked fine (Haxe/NodeJS/Python).
Could someone tell me what I am missing regarding using Reflect.callMethod with more than two arguments for Haxe Java-JVM target?
Thanks in advance.
Cheers