File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -111,9 +111,25 @@ instances of Node.js in a single process. Each instance will have its own
111111correctly when loaded via ` require() ` . From the addon's perspective, this means
112112that it must support multiple initializations.
113113
114- The macro ` NODE_MODULE_INIT() ` will construct an addon which supports such a use
115- case. Unlike ` NODE_MODULE() ` , which is used to construct an addon around an
116- addon initializer such as ` Initialize ` in the above example,
114+ A context-aware addon can be constructed by using the macro
115+ ` NODE_MODULE_INITIALIZER ` , which expands to the name of a function which Node.js
116+ will expect to find when it loads an addon. An addon can thus be initialized as
117+ in the following example:
118+
119+ ``` cpp
120+ using namespace v8 ;
121+
122+ extern "C" NODE_MODULE_EXPORT void
123+ NODE_MODULE_INITIALIZER (Local<Object > exports,
124+ Local<Value > module,
125+ Local<Context > context) {
126+ /* Perform addon initialization steps here. * /
127+ }
128+ ```
129+
130+ Another option is to use the macro `NODE_MODULE_INIT()`, which will also
131+ construct a context-aware addon. Unlike `NODE_MODULE()`, which is used to
132+ construct an addon around a given addon initializer function,
117133`NODE_MODULE_INIT()` serves as the declaration of such an initializer to be
118134followed by a function body.
119135
You can’t perform that action at this time.
0 commit comments