Last active
January 6, 2023 03:04
-
-
Save xeecos/29e35656b90a1b925688bab9a2ee71a3 to your computer and use it in GitHub Desktop.
node-gyp example
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 <node.h> | |
using v8::FunctionCallbackInfo; | |
using v8::Isolate; | |
using v8::Local; | |
using v8::Object; | |
using v8::String; | |
using v8::Value; | |
void Method(const FunctionCallbackInfo<Value> &args) | |
{ | |
Isolate *isolate = args.GetIsolate(); | |
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world").ToLocalChecked()); | |
} | |
void init(Local<Object> exports) | |
{ | |
NODE_SET_METHOD(exports, "hello", Method); | |
} | |
NODE_MODULE(addon, init) |
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': 'mybinding', | |
'sources': [ 'binding.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
const assert = require('assert'); | |
const binding = require('./build/Release/mybinding'); | |
assert.equal('world', binding.hello()); | |
console.log('binding.hello() =', binding.hello()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment