mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
doc: clarify that N-API addons are context-aware
The docs on N-API say that NAPI_MODULE_INIT must be used for the addon to be context-aware. That seems to be wrong, i.e. all N-API addons are context-aware(?) PR-URL: https://github.com/nodejs/node/pull/36640 Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
This commit is contained in:
1 parent
8f48e77217
commit
844a15622f
1 file changed
+5
-9
+5
-9
@@ -1841,8 +1841,8 @@ napi_value Init(napi_env env, napi_value exports) {
|
||||
}
|
||||
```
|
||||
|
||||
If the module will be loaded multiple times during the lifetime of the Node.js
|
||||
process, use the `NAPI_MODULE_INIT` macro to initialize the module:
|
||||
You can also use the `NAPI_MODULE_INIT` macro, which acts as a shorthand
|
||||
for `NAPI_MODULE` and defining an `Init` function:
|
||||
|
||||
```c
|
||||
NAPI_MODULE_INIT() {
|
||||
@@ -1859,13 +1859,9 @@ NAPI_MODULE_INIT() {
|
||||
}
|
||||
```
|
||||
|
||||
This macro includes `NAPI_MODULE`, and declares an `Init` function with a
|
||||
special name and with visibility beyond the addon. This will allow Node.js to
|
||||
initialize the module even if it is loaded multiple times.
|
||||
|
||||
There are a few design considerations when declaring a module that may be loaded
|
||||
multiple times. The documentation of [context-aware addons][] provides more
|
||||
details.
|
||||
All N-API addons are context-aware, meaning they may be loaded multiple
|
||||
times. There are a few design considerations when declaring such a module.
|
||||
The documentation on [context-aware addons][] provides more details.
|
||||
|
||||
The variables `env` and `exports` will be available inside the function body
|
||||
following the macro invocation.
|
||||
|
||||
Reference in new issue
Block a user