macro_rules! ffi_call { { ( $fun:expr ) ( $( $arg:expr ),* ) -> $ty:ty } => { ... }; { $fun:ident ( $( $arg:expr ),* ) -> $ty:ty } => { ... }; { ( $fun:expr ) ( $( $arg:expr ),* ) } => { ... }; { $fun:ident ( $( $arg:expr ),* ) } => { ... }; }
Expand description
Performs a dynamic call to a C function.
This macro provides sugar for high::arg
and
high::call
. For more control, see
high::call
.
Examples
extern "C" fn hypot(x: f32, y: f32) -> f32 {
(x * x + y * y).sqrt()
}
use libffi::ffi_call;
let result = unsafe { ffi_call!{ hypot(3f32, 4f32) -> f32 } };
assert!((result - 5f32).abs() < 0.0001);