node_api_create_external_string_latin1


稳定性: 1 - 实验性的

¥Stability: 1 - Experimental

napi_status
node_api_create_external_string_latin1(napi_env env,
                                       char* str,
                                       size_t length,
                                       napi_finalize finalize_callback,
                                       void* finalize_hint,
                                       napi_value* result,
                                       bool* copied); 
  • [in] env:调用 API 的环境。

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

  • [in] str:表示 ISO-8859-1 编码字符串的字符缓冲区。

    ¥[in] str: Character buffer representing an ISO-8859-1-encoded string.

  • [in] length:字符串的长度(以字节为单位),如果它以 null 结尾则为 NAPI_AUTO_LENGTH

    ¥[in] length: The length of the string in bytes, or NAPI_AUTO_LENGTH if it is null-terminated.

  • [in] finalize_callback:收集字符串时调用的函数。该函数将使用以下参数调用:

    ¥[in] finalize_callback: The function to call when the string is being collected. The function will be called with the following parameters:

    • [in] env:加载项运行的环境。如果字符串是作为工作线程或主 Node.js 实例终止的一部分而被收集的,则该值可能为 null。

      ¥[in] env: The environment in which the add-on is running. This value may be null if the string is being collected as part of the termination of the worker or the main Node.js instance.

    • [in] data:这是作为 void* 指针的值 str

      ¥[in] data: This is the value str as a void* pointer.

    • [in] finalize_hint:这是赋予 API 的值 finalize_hintnapi_finalize 提供了更多详细信息。该参数是可选的。传递 null 值意味着在收集相应的 JavaScript 字符串时不需要通知加载项。

      ¥[in] finalize_hint: This is the value finalize_hint that was given to the API. napi_finalize provides more details. This parameter is optional. Passing a null value means that the add-on doesn't need to be notified when the corresponding JavaScript string is collected.

  • [in] finalize_hint:在收集期间传递给最终回调的可选提示。

    ¥[in] finalize_hint: Optional hint to pass to the finalize callback during collection.

  • [out] result:代表 JavaScript stringnapi_value

    ¥[out] result: A napi_value representing a JavaScript string.

  • [out] copied:字符串是否被复制。如果是,则终结器将已被调用来销毁 str

    ¥[out] copied: Whether the string was copied. If it was, the finalizer will already have been invoked to destroy str.

如果 API 成功,则返回 napi_ok

¥Returns napi_ok if the API succeeded.

此 API 从 ISO-8859-1 编码的 C 字符串创建一个 JavaScript string 值。原生字符串不能被复制,因此必须在 JavaScript 值的整个生命周期中存在。

¥This API creates a JavaScript string value from an ISO-8859-1-encoded C string. The native string may not be copied and must thus exist for the entire life cycle of the JavaScript value.

JavaScript string 类型在 ECMAScript 语言规范的 第 6.1.4 节 中进行了描述。

¥The JavaScript string type is described in Section 6.1.4 of the ECMAScript Language Specification.