Function CFunction

  • 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

    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.

    Parameters

    Returns CallableFunction & { close: any }

  • 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

    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.

    Parameters

    Returns CallableFunction & { close: any }

Generated using TypeDoc