error: no matching function for call to 'Cast'
static void CsoundMessageCallback(CSOUND *Csound, int attributes,
const char *format, va_list valist)
static void _wrap_csoundSetMessageCallback(
const v8::FunctionCallbackInfo<v8::Value>& args)
// Pretend we get the Csound instance from args here. This is actually done
// by SWIG <http://www.swig.org>.
// This does not compile. csoundGetHostData() returns a void *, but I’m assuming
v8::Persistent<v8::Object> hostData =
Typically what I've done in situations like this is I write a wrapper C++ class (inheriting from node's ObjectWrap class) that stores a pointer to the instance of whatever C/C++ class I'm wrapping and has various public methods to interact with that instance.
new is called from JS land, a new instance of the wrapper C++ class gets created and associated with the new JS object. Then you have JS functions that kick off whatever async tasks that utilize the wrapped library's callbacks.
From there it's just a matter of calling
uv_async_send() from the wrapped library's callbacks to signal the main thread and then calling the JS callback from the uv_async callback.
You can see an example of all of this here (especially in the Windows-specific parts):
Pcapclass holds a
pcap_tpointer (would be a
CSOUNDpointer for you).
Pcapis created from JS land, I wrap a new C++ class instance.
uv_async_twhich sets up the callback to fire on
uv_async_send()and also associates the user data pointer to the class instance for easy access. You could do this initialization during the call to
newif you wanted, instead of a separate prototype function (
open()) like I have done since initialization just happens once.
As far as storing JS callbacks goes, there are different ways to handle that. One solution might be to create a baton object that stores a Persistent copy of the JS callback and the wrapper class instance and store that baton in
uv_async_t's user data pointer. This would mean creating a new
uv_async_t for every request (which is different than the example I gave above).