napi_get_version


napi_status napi_get_version(node_api_basic_env env,
                             uint32_t* result); 
  • [in] env:调用 API 的环境。

    ¥[in] env: The environment that the API is invoked under.

  • [out] result:支持的最高版本的 Node-API。

    ¥[out] result: The highest version of Node-API supported.

如果 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 是否可用。

    ¥Call napi_get_version() to determine if the API is available.

  • 如果可用,使用 uv_dlsym() 动态加载指向函数的指针。

    ¥If available, dynamically load a pointer to the function using uv_dlsym().

  • 使用动态加载的指针来调用函数。

    ¥Use the dynamically loaded pointer to invoke the function.

  • 如果该函数不可用,请提供不使用该函数的替代实现。

    ¥If the function is not available, provide an alternate implementation that does not use the function.