调用本地函数
🌐 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 位整数类型(int64 和 uint64),请传入在声明类型范围内的 JavaScript bigint 值或安全整数 number 值。对于 int64,数字必须在 Number.MIN_SAFE_INTEGER 和 Number.MAX_SAFE_INTEGER 之间(含端点)。对于 uint64,数字必须在 0 和 Number.MAX_SAFE_INTEGER 之间(含端点)。这样就可以传递像 buffer.byteLength 这样的缓冲区长度,而无需显式的 BigInt() 转换。对于超出 JavaScript 安全整数范围的整数,请使用 bigint。
🌐 For 64-bit integer types (int64 and uint64), pass JavaScript bigint
values within the declared type's range or safe integer number values.
For int64, numbers must be between Number.MIN_SAFE_INTEGER and
Number.MAX_SAFE_INTEGER, inclusive. For uint64, numbers must be between
0 and Number.MAX_SAFE_INTEGER, inclusive. This allows buffer lengths such
as buffer.byteLength to be passed without an explicit BigInt() conversion.
Use bigint for integers outside JavaScript's safe integer range.
无效的参数,包括小数、NaN、无穷大以及超出这些范围的值,会抛出 ERR_INVALID_ARG_VALUE。64 位整数类型的返回值总是以 bigint 值的形式出现。
🌐 Invalid arguments, including fractional numbers, NaN, infinities, and values
outside these ranges, throw ERR_INVALID_ARG_VALUE. Return values for 64-bit
integer types are always exposed as bigint values.
对于指针类参数:
🌐 For pointer-like arguments:
null和undefined被传递为空指针。string值在调用期间被复制到临时的 NUL 结尾 UTF-8 字符串中。Buffer、类型化数组和DataView实例会传递一个指向其后备内存的指针。ArrayBuffer传递其底层内存的指针。bigint值作为原始指针地址传递。
指针返回值以 bigint 地址的形式显示。
🌐 Pointer return values are exposed as bigint addresses.