Skip to content

Instantly share code, notes, and snippets.

@gabrielschulhof
Created October 9, 2015 13:37
Show Gist options
  • Save gabrielschulhof/1ed984b64627c35c837e to your computer and use it in GitHub Desktop.
Save gabrielschulhof/1ed984b64627c35c837e to your computer and use it in GitHub Desktop.
#include <nan.h>
#include <node.h>
#include <v8.h>
using namespace v8;
int counter = 0;
extern void doSomething();
NAN_METHOD( bind_OCProcess ) {
NanScope();
doSomething();
counter++;
if ( counter >= 5 ) {
NanThrowTypeError( "Some error" );
NanReturnValue( NanNull() );
}
NanReturnValue( NanNew<Object>() );
}
void Init(Handle<Object> exports, Handle<Object> module) {
exports->Set( NanNew<String>( "OCProcess" ),
NanNew<FunctionTemplate>( bind_OCProcess )->GetFunction() );
}
NODE_MODULE( addonexample, Init )
{
"targets": [
{
"target_name": "addonexample",
"sources": [ "addonexample.cc" ],
"include_dirs" : [
"<!(node -e \"require('nan')\")"
]
}
],
}
var addon = require( "bindings" )( "addonexample" );
setInterval( function() {
// console.log( addon.OCProcess() );
}, 1000 );
{
"name": "addonexample",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"bindings": "^1.2.1",
"nan": "^1.8.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment