Interface FFIFunction

Hierarchy

  • FFIFunction

Properties

Properties

Arguments to a FFI function (C ABI)

Defaults to an empty array, which means no arguments.

To pass a pointer, use "ptr" or "pointer" as the type name. To get a pointer, see ptr.

Example

From JavaScript:

const lib = dlopen('add', {
// FFIType can be used or you can pass string labels.
args: [FFIType.i32, "i32"],
returns: "i32",
});
lib.symbols.add(1, 2)

In C:

int add(int a, int b) {
return a + b;
}
ptr?: number | bigint

Function pointer to the native function

If provided, instead of using dlsym() to lookup the function, Bun will use this instead. This pointer should not be null (0).

This is useful if the library has already been loaded or if the module is also using Node-API.

returns?: FFITypeOrString

Return type to a FFI function (C ABI)

Defaults to void

To pass a pointer, use "ptr" or "pointer" as the type name. To get a pointer, see ptr.

Example

From JavaScript:

const lib = dlopen('z', {
version: {
returns: "ptr",
}
});
console.log(new CString(lib.symbols.version()));

In C:

char* version()
{
return "1.0.0";
}

Generated using TypeDoc