I'm creating an OpenFL extension for a mobile advertising SDK, and I'm having difficulty figuring out some CFFI stuff.
Basically, I'm trying to pass a Haxe object to C++, and then call a method on that object from C++. The purpose of this is as an event listener, so when something happens in C++, I will call a callback on that object to notify the Haxe code.
I know how to do this with Java using lime's JNI stuff for Android. That looks something like this using JNI type signatures:
var setCallbackListener = JNI.createStaticMethod("com.test.myextension", "setCallbackListener", "(Lorg/haxe/lime/HaxeObject;)V");
var listener = new MyCallbackListener(); //implements `onSomething`
setCallbackListener(listener); //pass the listener to the Java side
Then from the Java side, I can call the function onSomething
like this:
public static void setCallbackListener(HaxeObject listener){
listener.call0("onSomething"); //call a function called "onSomething" with zero arguments
}
And that works, and it's how I'm doing it for Android. For iOS, I'm trying to do the same thing, but with hxcpp.
I know the general process for calling a C++ function from Haxe, using cpp.Lib.load
in a similar way to the JNI api above. However, once I get a value
type on the C++ side, I don't know how I can call a member function on it.
for example, say my C++ function looks like this:
#include <hx/CFFI.h>
static void setCallbackListener (value listener) {
//...
}
DEFINE_PRIM (setCallbackListener, 1);
How would I then call the function "onSomething" in listener
?