Skip to content

Instantly share code, notes, and snippets.

@gabrielschulhof
Created August 23, 2015 22:08
Show Gist options
  • Save gabrielschulhof/bd017094cd8aeb2e463c to your computer and use it in GitHub Desktop.
Save gabrielschulhof/bd017094cd8aeb2e463c to your computer and use it in GitHub Desktop.
#include <nan.h>
#include <node.h>
#include <v8.h>
using namespace v8;
int counter = 0;
NAN_METHOD( bind_OCProcess ) {
NanScope();
counter++;
if ( counter >= 5 ) {
NanThrowError( "Some error" );
}
NanReturnValue( NanNew<String>( "return value" ) );
}
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() {
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