napi_get_version
napi_status napi_get_version(node_api_basic_env env,
uint32_t* result); [in] env:调用该 API 时所处的环境。[out] result:支持的最高版本的 Node-API。
如果 API 成功,则返回 napi_ok。
【Returns napi_ok if the API succeeded.】
此 API 返回 Node.js 运行时支持的最高 Node-API 版本。Node-API 计划是增量添加的,这样较新的 Node.js 版本可能会支持额外的 API 函数。为了允许一个插件在运行支持该函数的 Node.js 版本时使用较新的函数,同时在运行不支持该函数的 Node.js 版本时提供备用行为:
【This API returns the highest Node-API version supported by the Node.js runtime. Node-API is planned to be additive such that newer releases of Node.js may support additional API functions. In order to allow an addon to use a newer function when running with versions of Node.js that support it, while providing fallback behavior when running with Node.js versions that don't support it:】
- 调用
napi_get_version()来确定该 API 是否可用。 - 如果可用,使用
uv_dlsym()动态加载指向该函数的指针。 - 使用动态加载的指针来调用函数。
- 如果该函数不可用,请提供一个不使用该函数的替代实现。