Skip to main content

Function: dlopenCProto()

dlopenCProto(path, header): DlopenCProtoResult

Load a shared library and bind every function declared in a C header snippet, which also defines the structs and typedefs those functions use.

import { dlopenCProto, Pointer } from 'tjs:ffi';

const { symbols, types, close } = dlopenCProto('./libfoo.dylib', `
struct point { int x; int y; };
int distance(struct point* a, struct point* b);
`);

const point = types.get('struct point');

console.log(symbols.distance(
Pointer.createRef(point, { x: 0, y: 0 }),
Pointer.createRef(point, { x: 3, y: 4 })));
close();

Parameters

path

string

Path to the shared library, or 'c' / 'm' for the platform's C and math libraries, whose file names differ per platform.

string

C declarations: function prototypes, structs, typedefs.

Returns

DlopenCProtoResult