Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Working with raw C function pointers via CFunction
CFunction
const handle = ffi.load('libffi_target.so'); const ptr = ffi.getSymbolPtr(handle, 'add'); // ptr is the memory address of the C function
import { CFunction, FFIType } from 'arkffi'; const add = CFunction({ args: [FFIType.double, FFIType.double], returns: FFIType.double, ptr: ptr, }); add(2.0, 3.0); // → 5.0 add.close();
const fn = CFunction({ ... }); fn(); fn.close();
// C: void sort(int* arr, int (*cmp)(int, int)); const cmp = CFunction({ args: ['i', 'i'], returns: 'i', ptr: cmpPtr }); ffi.callMixed(handle, 'sort', 'ip', 'v', [arrPtr, cmp.ptr], []);
JSCallback
const cmp = new JSCallback( (a: number, b: number): number => a - b, { args: [FFIType.int32, FFIType.int32], returns: FFIType.int32 }, ); ffi.callMixed(handle, 'sort', 'ip', 'v', [arrPtr, cmp.ptr], []); cmp.close();
Was this page helpful?