forked from nodejs/node-addon-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddon.cc
More file actions
21 lines (15 loc) · 652 Bytes
/
addon.cc
File metadata and controls
21 lines (15 loc) · 652 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <nan.h>
void MyFunction(const Nan::FunctionCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(Nan::New("hello world").ToLocalChecked());
}
void CreateFunction(const Nan::FunctionCallbackInfo<v8::Value>& info) {
v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(MyFunction);
v8::Local<v8::Function> fn = tpl->GetFunction();
// omit this to make it anonymous
fn->SetName(Nan::New("theFunction").ToLocalChecked());
info.GetReturnValue().Set(fn);
}
void Init(v8::Local<v8::Object> exports, v8::Local<v8::Object> module) {
Nan::SetMethod(module, "exports", CreateFunction);
}
NODE_MODULE(addon, Init)