FFIFunction declaration. ptr
is required
Turn a native library's function pointer into a JavaScript function
Libraries using Node-API & bun:ffi in the same module could use this to skip an extra dlopen() step.
import {CFunction} from 'bun:ffi';
const getVersion = new CFunction({
returns: "cstring",
args: [],
ptr: myNativeLibraryGetVersion,
});
getVersion();
getVersion.close();
This is powered by just-in-time compiling C wrappers that convert JavaScript types to C types and back. Internally, bun uses tinycc, so a big thanks goes to Fabrice Bellard and TinyCC maintainers for making this possible.
FFIFunction declaration. ptr
is required
Generated using TypeDoc
Turn a native library's function pointer into a JavaScript function
Libraries using Node-API & bun:ffi in the same module could use this to skip an extra dlopen() step.
Example
This is powered by just-in-time compiling C wrappers that convert JavaScript types to C types and back. Internally, bun uses tinycc, so a big thanks goes to Fabrice Bellard and TinyCC maintainers for making this possible.