Skip to content

Commit 9402ca1

Browse files
author
Gabriel Schulhof
committed
document NODE_MODULE_INITIALIZER
1 parent a9d8063 commit 9402ca1

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

doc/api/addons.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,25 @@ instances of Node.js in a single process. Each instance will have its own
111111
correctly when loaded via `require()`. From the addon's perspective, this means
112112
that 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
118134
followed by a function body.
119135

0 commit comments

Comments
 (0)