ffi
Foreign function interface for calling symbols in shared libraries.
Import
import ffiFunctions
ffi.load(path: str) -> lib
Open a shared library (.so, .dylib, or .dll), returning a library handle.
ffi.sym(lib: lib, name: str) -> sym
Resolve a symbol from a loaded library by name.
ffi.call(sym: sym, ret_type: str, arg_types: [str], args: [any]) -> any
Invoke a resolved symbol. Type strings include "double", "int", "str", "void".
ffi.close(lib: lib)
Release a library handle.
ffi.typeof(value: any) -> str
Return the FFI type tag for a value.
Examples
import ffi
let lib = ffi.load("libm.so.6")
let cos_fn = ffi.sym(lib, "cos")
let result = ffi.call(cos_fn, "double", ["double"], [0.0])
println(result) -- 1.0
ffi.close(lib)