Expand description
This library provides a convenient interface for loading dynamic libraries
at runtime, and for retrieving symbols from them. The recommended use is
via the snek!
macro, which defines a structure which
loads symbols on construction and has methods for each one, however it is
also possible to manually load libraries and symbols using a Snek
instance.
§Safety
There is no way of verifying the type of loaded symbols, so both methods of using them assume that the given type is correct - this library should be used very carefully. Consider everything very unstable at the moment.
§Example
#[macro_use] extern crate snek;
extern crate libc;
use libc::c_int;
snek! {
Example {
hello: () -> (),
add: (x: c_int, y: c_int) -> c_int
}
}
fn main() {
if let Ok(example) = Example::load("libexample.so") {
unsafe { example.hello() };
println!("2 + 4 = {}", unsafe { example.add(2, 4) });
}
}
Macros§
- snek
- This macro is used to generate a struct that wraps a dynamic library with generated loading code. Each defined function will be loaded as a symbol from the library when an instance of the struct is constructed, and can be called via functions of the same name attached to the struct.
Structs§
- Snek
- This provides an interface for manually loading a dynamic library and
symbols from it. While this exists, it is more recommended to use the
snek!
macro to generate a wrapper for a library automatically. - Symbol
- This provides an interface around a symbol loaded from a
dynamic library. This should not be constructed manually,
but returned from
Snek::symbol
or used internally via thesnek!
macro.
Enums§
- Error
- This enum stores information about the error returned when loading a library
or symbol fails. On unix platforms, it hold the result of
dlerror()
.