Adding a macro to give structure to the linking of external libraries.

This commit is contained in:
Myrddin Dundragon 2019-06-24 21:04:52 -04:00
parent 9d2c092463
commit 9e1fee89ad
2 changed files with 34 additions and 0 deletions

View File

@ -24,6 +24,9 @@ mod c_types;
// Raw platform data retrieval.
mod raw;
// Macros to help create bindings to FFI libraries.
mod macros;
pub use self::c_types::{CChar, CUChar};

31
src/macros.rs Normal file
View File

@ -0,0 +1,31 @@
#[macro_export]
macro_rules! external_library
{
{
$name: ident : $link: ident
{
$(statics:
$($sname: ident: $stype: ty),+;
)|*
$(functions:
$($fname: ident($($farg: ty),*) -> $fret:ty),+;
)|*
$(varargs:
$($vname: ident($($vargs: ty),+) -> $vret: ty),+;
)|*
}
} =>
{
#[link(name=$link)]
extern "C"
{
$($(pub static $sname: $stype;)+)*
$($(pub fn $fname($(_: $farg),*) -> $fret;)+)*
$($(pub fn $vname($(_: $vargs),+ , ...) -> $vret;)+)*
}
}
}