Last active
August 31, 2016 13:50
-
-
Save ironman9967/7681637 to your computer and use it in GitHub Desktop.
node-addon
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 <node.h> | |
using namespace v8; | |
struct point { | |
int x; | |
int y; | |
}; | |
void pointerFunction(point* p) { | |
p->x = 99; | |
p->y = 11; | |
} | |
Handle<Value> GetPoint(const Arguments& args) { | |
HandleScope scope; | |
point* p = new point; | |
pointerFunction(p); | |
Local<Object> obj = Object::New(); | |
obj->Set(String::NewSymbol("x"), Number::New(p->x)); | |
obj->Set(String::NewSymbol("y"), Number::New(p->y)); | |
delete p; | |
return scope.Close(obj); | |
} | |
void InitAll(Handle<Object> exports) { | |
exports->Set(String::NewSymbol("GetPoint"), FunctionTemplate::New(GetPoint)->GetFunction()); | |
} | |
NODE_MODULE(addon, InitAll) |
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('./build/Release/addon'); | |
setInterval(function () { | |
console.log(addon.GetPoint()); | |
}, 100); |
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": "addon", | |
"sources": [ "addon.cc" ] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment