Last active
August 29, 2015 14:27
-
-
Save ghaiklor/ac22b0ce38f23847e00b to your computer and use it in GitHub Desktop.
NodeJS example how native modules is loading
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 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