Skip to content

Instantly share code, notes, and snippets.

@xeecos
Last active January 6, 2023 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeecos/29e35656b90a1b925688bab9a2ee71a3 to your computer and use it in GitHub Desktop.
Save xeecos/29e35656b90a1b925688bab9a2ee71a3 to your computer and use it in GitHub Desktop.
node-gyp example
#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)
{
'targets': [
{
'target_name': 'mybinding',
'sources': [ 'binding.cc' ]
}
]
}
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