Skip to content

Instantly share code, notes, and snippets.

/addon.cpp Secret

Created December 5, 2016 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/60cdc8562c3c6466046b12f8544ad0d1 to your computer and use it in GitHub Desktop.
Save anonymous/60cdc8562c3c6466046b12f8544ad0d1 to your computer and use it in GitHub Desktop.
/* wrapper.cpp */
void SetProcessEmitter(const FunctionCallbackInfo<Value> &args)
{
Nan::Callback *callback = new Nan::Callback(args[0].As<Function>());
setProcessEmit(callback);
}
/* handlers.cpp */
void asyncmsg(uv_async_t *handle)
{
Nan::HandleScope scope;
v8::Isolate *isolate = v8::Isolate::GetCurrent();
Local<Value> args[] = {
String::NewFromUtf8(isolate, "test"),
String::NewFromUtf8(isolate, readableData),
};
cb->Call(2, args);
}
void setProcessEmit(Nan::Callback *callback)
{
cb = callback;
loop = uv_default_loop();
uv_async_init(loop, &async, asyncmsg);
}
/* init.js */
// Load addon
const t = require('./build/Release/addon');
// Connect to the scanner
t.start();
// Logging function
var f = function f(i) { console.log(i); };
// Display everything caught from this event
process.on("test", f);
// Send function to use -> Call first function in this gist
t.setProcessEmitter(process.emit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment