调用本地函数


🌐 Calling native functions

参数转换取决于声明的 FFI 类型。

🌐 Argument conversion depends on the declared FFI type.

对于 8 位、16 位和 32 位整数类型以及浮点类型,请传递与声明类型匹配的 JavaScript number 值。

🌐 For 8-, 16-, and 32-bit integer types and for floating-point types, pass JavaScript number values that match the declared type.

对于 64 位整数类型(i64u64),传递 JavaScript bigint 值。

🌐 For 64-bit integer types (i64 and u64), pass JavaScript bigint values.

对于指针类参数:

🌐 For pointer-like parameters:

  • nullundefined 被传递为空指针。
  • string 值在调用期间被复制到临时的 NUL 结尾 UTF-8 字符串中。
  • Buffer、类型化数组和 DataView 实例会传递一个指向其后备内存的指针。
  • ArrayBuffer 传递其底层内存的指针。
  • bigint 值作为原始指针地址传递。

指针返回值以 bigint 地址的形式显示。

🌐 Pointer return values are exposed as bigint addresses.