Adding a macro to give structure to the linking of external libraries.
This commit is contained in:
parent
9d2c092463
commit
9e1fee89ad
@ -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
31
src/macros.rs
Normal 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;)+)*
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user