Function: dlopen()
dlopen<
T>(path,symbols):DlopenResult<T>
Load a shared library and bind symbols as callable functions.
Types can be specified as SimpleType objects or as string aliases
(e.g. 'i32', 'string', 'ptr').
import { dlopen } from 'tjs:ffi';
const { symbols, close } = dlopen('./libfoo.dylib', {
add: { args: ['i32', 'i32'], returns: 'i32' },
version: { args: [], returns: 'string' },
});
console.log(symbols.add(1, 2));
console.log(symbols.version());
close();
Type Parameters
T
T extends Record<string, DlopenSymbol>
Parameters
path
string
Path to the shared library.
symbols
T
Object mapping symbol names to their type signatures.
Returns
DlopenResult<T>