How do I convert V8 objects to pointers?
The high level answer is that you don't pass the JS callback function directly, but pass in a pointer to a function that somehow has your JS callback as a context value (in your example the priv
parameter).
So for your case you write something like this:
void TheLibraryCallback(context ctx, void *instance, struct X *the_reply) { ((TheLibrary*)instance)->callback(ctx, the_reply);}
In your TheLibrary
you add a method void callback(context ctx, struct X * the_reply)
that handles the callback. You call your library like this: lib_send_message(ctx, msg, TheLibraryCallback, this);
with this
being a TheLibrary
instance.
So how do you call back the JS callback in your callback method? With nan
you will have to make sure you are back in the main thread. There are examples out there, but I would suggest that you use the new N-API instead. The AsyncWorker helps with the boilerplate that you need to do to call the callback in the main thread.