napi_create_function

Function napi_create_function 

Source
pub unsafe extern "C" fn napi_create_function(
    env: napi_env,
    utf8name: *const c_char,
    length: usize,
    cb: napi_callback,
    data: *mut c_void,
    result: *mut napi_value,
) -> napi_status
Available on crate feature napi only.
Expand description

Create an ArkTS function. This is the primary mechanism to call back into native code from ArkTS.

§Arguments

  • env - Current running virtual machine context.

  • utf8name - The visible within ArkTS as the new function’s name property.

  • length - The length oh the utf8name, or NAPI_AUTO_LENGTH if it is null-terminated.

  • cb - The native function which should be called when this function object is called.

  • data - User-provided data context. This will be passed back into the function when invoked.

  • result - The newly created ArkTS function.

§Returns

  • Returns the function execution status. [napi_ok] If the function executed successfully.

[napi_invalid_arg] If the param env, cb and(or) result is nullptr.

[napi_pending_exception] There is an uncaught exception occurred before(in) execution.

Available since API-level: 10