Optional
argsOptional
ptrFunction 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.
Optional
returnsReturn 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.
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
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:
In C: