Maybe I just don't search for the right terms but I'm stuck..
I need to call a JavaScript function from C++, very similar to what can be done using the plain C API.
Note: I don't want to pass a callback to the C++ code but I already know the name of the function to be called!
So for example I have a function like this in JavaScript:
function log_message_callback(context, message) {
console.log(`${context}: ${message}`);
}
my_napi_module.initialize(); // <-- starts thread that would call log_message_callback
And from C++ I want to call it (btw, from a thread different from the main thread):
#include <napi.h>
void log_message_callback(char const* message) {
// magic Napi code which would call log_message_callback in JavaScript
}
void some_thread_fn() {
log_message_callback("hello world");
}
Can I do this? How would I do this? And what should I have been looking for?!