ffi
dload loads a shared library, declare describes a C function’s signature
with the type tags from ffi::types, and
invoke calls it. An extern "lib" { … } block does the same at compile
time; see the FFI tutorial.
Loading is gated. A program can dload a library only when it is allowed with
--allow-dload NAME and either pinned by hash (--dload-pin NAME=SHA256) or
trusted (--dload-trusted NAME); --ffi-search-path DIR says where to look.
spool sets these from the project’s coil.toml and lockfile. The C library
(dload("c")) is always denied. Pin a Coil value with
gc::root before giving C a pointer it keeps.
Built into the compiler.
Import what you use (use path::* is not allowed):
use ffi::{ErrorKind, Error};
Modules#
| Module | Description |
|---|---|
ffi::types | Type tags that describe C argument and return types to ffi::declare. |
Types#
| Name | Description |
|---|---|
ErrorKind | The category of an FFI failure, read from Error.kind. |
Error | The error of dload, declare, invoke and read_ints. |
Functions#
| Name | Description |
|---|---|
dload | Loads a native shared library and returns a handle to it. |
declare | Looks up the C function name in a loaded library and records its signature. |
invoke | Calls a function registered with declare, passing the tuple args. |
read_ints | Copies count 64-bit integers (int64_t) from native memory at ptr. |