Created
October 9, 2015 13:37
-
-
Save gabrielschulhof/1ed984b64627c35c837e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"targets": [ | |
{ | |
"target_name": "addonexample", | |
"sources": [ "addonexample.cc" ], | |
"include_dirs" : [ | |
"<!(node -e \"require('nan')\")" | |
] | |
} | |
], | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var addon = require( "bindings" )( "addonexample" ); | |
setInterval( function() { | |
// console.log( addon.OCProcess() ); | |
}, 1000 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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