Hi,
I'm in the process of making a tool similar to webidl-binder. Right now I'm
trying to add support for callback interfaces, but I'm a bit stuck on how
to get this working.
What I would like to do is be able to make an implementation of a callback
interface in Javascript, pass it to C++ and then invoke methods on the
callback object. I'm trying to implement this using a lookup table where
callback objects get registered and assigned an id when first passed to
C++. On the C++ side a proxy object is created which wraps the id value and
dispatches member functions to functions defined in Javascript. Those
functions are included using the --js-library flag as per the documentation.
In the code below I've put the object lookup table inside the js-library.
The problem I have now is that I need some way to access that lookup table
(directly or indirectly) from Javascript code that isn't processed by
emscripten. I think the most reliable way to do this will be to export the
table via the Module object. My question is how I can do this. Is there any
way to force symbols defined in a js-library to be exported via Module? Or
is there an easier strategy to implement callbacks?
Thanks,
Pepijn
Example code showing the pattern I'm trying to implement follows.
In my test IDL file I have something like
interface Test {
void callMeBack(Callback c);
};
callback interface Callback {
void callback(Test t);
};
The C++ implementations for Test and Callback are (abbreviated)
void Test::callMeBack(Callback *cb) {
cb->callback(this);
}
class Callback {
int handle;
Callback(int handle) : handle(handle) {}
void callback(Test* test) {
js_callback_Callback_callback(this->handle, test);
}
};
extern "C" {
void emscripten_operation_Callback_callback(int handle, Test* test);
}
And finally the JS library looks like this
mergeInto(LibraryManager.library,{
$CALLBACK_OBJECTS: {
cache: []
},
emscripten_operation_Callback_callback: function (handle, test_ptr) {
CALLBACK_OBJECTS.cache[handle].callback(test_ptr);
}
});
--
You received this message because you are subscribed to the Google Groups
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.