Skip to content

Instantly share code, notes, and snippets.

View sagivo's full-sized avatar
👨‍💻
coding

Sagiv Ofek sagivo

👨‍💻
coding
View GitHub Profile
@sagivo
sagivo / binding.gyp
Last active September 30, 2015 16:53
{
"targets": [
{
"target_name": "addon",
"sources": [ "hello.cc" ]
}
]
}
all: build
build: build_node
build_node: node-gyp rebuild
@sagivo
sagivo / 6.cc
Created September 30, 2015 16:49
#include <nan.h>
@sagivo
sagivo / 2.json
Created September 30, 2015 16:49
"include_dirs" : ["<!(node -e \"require('nan')\")"]
@sagivo
sagivo / 5.cc
Created September 30, 2015 16:48
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());
}
@sagivo
sagivo / 4.cc
Created September 30, 2015 16:47
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());
}
@sagivo
sagivo / 3.cc
Created September 30, 2015 16:47
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());
}
@sagivo
sagivo / 2.cc
Created September 30, 2015 16:45
void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
}
@sagivo
sagivo / 1.cc
Last active September 30, 2015 16:44
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
```cpp
void init(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
```