diff options
author | Gabriel Schulhof <gabriel.schulhof@intel.com> | 2018-04-21 05:57:33 +0300 |
---|---|---|
committer | Gabriel Schulhof <gabriel.schulhof@intel.com> | 2018-04-24 00:24:18 +0300 |
commit | 0f8caf23bed91cbbb19121a3c97bb21c703258ac (patch) | |
tree | bed3a70a6a81276e7c1ed8a99712ecf1e567e2ef /src/node_api.h | |
parent | 3bcd8576fcb800077c922233da251a2299b66923 (diff) |
n-api: initialize a module via a special symbol
Much like regular modules, N-API modules can also benefit from having
a special symbol which they can expose.
Fixes: https://github.com/nodejs/node/issues/19845
PR-URL: https://github.com/nodejs/node/pull/20161
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/node_api.h')
-rw-r--r-- | src/node_api.h | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/node_api.h b/src/node_api.h index aaf002b7584..b010d32db7b 100644 --- a/src/node_api.h +++ b/src/node_api.h @@ -90,9 +90,28 @@ typedef struct { } \ EXTERN_C_END -#define NAPI_MODULE(modname, regfunc) \ +#define NAPI_MODULE(modname, regfunc) \ NAPI_MODULE_X(modname, regfunc, NULL, 0) // NOLINT (readability/null_usage) +#define NAPI_MODULE_INITIALIZER_BASE napi_register_module_v + +#define NAPI_MODULE_INITIALIZER_X(base, version) \ + NAPI_MODULE_INITIALIZER_X_HELPER(base, version) +#define NAPI_MODULE_INITIALIZER_X_HELPER(base, version) base##version + +#define NAPI_MODULE_INITIALIZER \ + NAPI_MODULE_INITIALIZER_X(NAPI_MODULE_INITIALIZER_BASE, \ + NAPI_MODULE_VERSION) + +#define NAPI_MODULE_INIT() \ + EXTERN_C_START \ + NAPI_MODULE_EXPORT napi_value \ + NAPI_MODULE_INITIALIZER(napi_env env, napi_value exports); \ + EXTERN_C_END \ + NAPI_MODULE(NODE_GYP_MODULE_NAME, NAPI_MODULE_INITIALIZER) \ + napi_value NAPI_MODULE_INITIALIZER(napi_env env, \ + napi_value exports) + #define NAPI_AUTO_LENGTH SIZE_MAX EXTERN_C_START |