I’m interfacing scala to some native code (through java+jna) and am about to rewrite the api using tuples and multiple return parameters. But I’m wondering if there’s a better way (with implicits or something).
For example, I may have a method signature like
MyLib.__stdcall aMethod(String inParam, String[] out1, int[] out2);
Where the arrays are there so I can get the values in java:
String[] out1 = new String[1];
Int[] out2 = new Int[1];
lib.aMethod("in", out1, out2);
String theRealOut1Value = out1[0];
Int theRealOut2Value = out2[0];
and Voila! How simple!
I’m pretty sure the only reasonable thing to do is make a wrapper with a (scala) method sig like:
aMethodWrapper(in : String) : (String, Int)
I’m not hopeful, but I’m seeing magic at every turn in scala, so I was wondering 🙂
You can create the following helper function:
…and for two arguments:
After that you may call the library functions like this:
and