dload
fn dload(string path) -> Result<int, Error> Import
Source: use ffi::{dload}; compiler/src/builtin_docs/ffi.hy Loads a native shared library and returns a handle to it.
path is a stem ("sum" finds libsum.so, libsum.dylib or sum.dll
in the --ffi-search-path directories), a relative path or an absolute
path. Every library is gated by its file-name stem: the build needs
--allow-dload STEM (a literal stem without it is error E0410, and a
non-literal path is E0411; -A does not grant it), and at run time the
stem also needs --dload-pin STEM=SHA256 or --dload-trusted STEM. A
denied load is Err with ErrorKind::Other. The libc aliases
(dload("c")) are always denied.
Returns Err with ErrorKind::LibraryNotFound when the stem is allowed
but no file is found.
Parameters#
| Name | Type |
|---|---|
path | string |
Returns#
Result<int, Error>
Examples#
use ffi::{dload, ErrorKind};
// coil --allow-dload sum --dload-trusted sum --ffi-search-path native app.hy
let lib = match dload("sum") {
Result::Ok(h) => h,
Result::Err(e) => match e.kind {
ErrorKind::LibraryNotFound => panic "build libsum first",
default => panic e.message,
},
};
See also#
ffi::ErrorKinddeclare: Looks up the C functionnamein a loaded library and records its signature.invoke: Calls a function registered withdeclare, passing the tupleargs.read_ints: Copiescount64-bit integers (int64_t) from native memory atptr.