Runtime method for getting number of parameters in anonymous function?

The following way of getting the number of parameters of an anon function at runtime works in JS,
but not on Eval or Cpp. (Haven’t tried other platforms.)
I there any other runtime way, or do I have to go the macro route?

function main() {
	var callback = (v:Int, a:String) -> {
		trace(v);
	};

	var length:Null<Int> = Reflect.getProperty(callback, 'length');
	trace(length); // Works in JS, but gives null in Eval, CPP...
}

Using a macro to find out the number of args of a function with a known signature is trivial, but I’m not sure what that would really accomplish: Try Haxe !

Perhaps some context would help for offering a practical solution :wink:

1 Like