This file contains 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": [ "hello.cc" ] | |
} | |
] | |
} |
This file contains 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
all: build | |
build: build_node | |
build_node: node-gyp rebuild |
This file contains 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> |
This file contains 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_dirs" : ["<!(node -e \"require('nan')\")"] |
This file contains 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
void GetBuffer(const FunctionCallbackInfo<Value>& args) { | |
char *data; | |
size_t length; | |
GetSomeBufferData(data, length); | |
MaybeLocal<Object> buffer = Nan::CopyBuffer(data, length); | |
delete []data; | |
args.GetReturnValue().Set(buffer.ToLocalChecked()); | |
} |
This file contains 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
void GetBuffer(const FunctionCallbackInfo<Value>& args) { | |
char *data; | |
size_t length; | |
GetSomeBufferData(data, length); | |
MaybeLocal<Object> buffer = Nan::NewBuffer(data, length); | |
args.GetReturnValue().Set(buffer.ToLocalChecked()); | |
} |
This file contains 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
void Method(const FunctionCallbackInfo<Value>& args) { | |
v8::String::Utf8Value nameFromArgs(args[0]->ToString()); | |
std::string name = std::string(*nameFromArgs); | |
std::string response = "hello " + name; | |
args.GetReturnValue().Set(Nan::New(response).ToLocalChecked()); | |
} |
This file contains 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
void Method(const FunctionCallbackInfo<Value>& args) { | |
Isolate* isolate = args.GetIsolate(); | |
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world")); | |
} |
This file contains 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
void init(Local<Object> exports) { | |
NODE_SET_METHOD(exports, "hello", Method); | |
} |
This file contains 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
```cpp | |
void init(Local<Object> exports) { | |
NODE_SET_METHOD(exports, "hello", Method); | |
} | |
``` |