Skip to content

Instantly share code, notes, and snippets.

@ghaiklor
Last active August 29, 2015 14:27
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 ghaiklor/ac22b0ce38f23847e00b to your computer and use it in GitHub Desktop.
Save ghaiklor/ac22b0ce38f23847e00b to your computer and use it in GitHub Desktop.
NodeJS example how native modules is loading
// Include header files here
namespace node {
// Using namespaces
// Define useful macros
// And a lot other stuff here in C++
void UpdateHeapStatisticsArrayBuffer(const FunctionCallbackInfo<Value>& args) {
// Some logic here...
}
void SetFlagsFromString(const FunctionCallbackInfo<Value>& args) {
// And here...
}
// Our regfunc method that accepts exports ObjectTemplate as target
void InitializeV8Bindings(Handle<Object> target, Handle<Value> unused, Handle<Context> context) {
Environment* env = Environment::GetCurrent(context);
env->SetMethod(target, "updateHeapStatisticsArrayBuffer", UpdateHeapStatisticsArrayBuffer);
env->SetMethod(target, "setFlagsFromString", SetFlagsFromString);
target->Set(
FIXED_ONE_BYTE_STRING(env->isolate(), "heapStatisticsArrayBuffer"),
ArrayBuffer::New(env->isolate(), env->heap_statistics_buffer(), heap_statistics_buffer_byte_length)
);
}
NODE_MODULE_CONTEXT_AWARE_BUILTIN(v8, node::InitializeV8Bindings)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment