Finally nailed down the syntax of the external_library macro.

This commit is contained in:
Myrddin Dundragon 2019-06-25 01:52:27 -04:00
parent 4028c5c618
commit 95361a80e2
2 changed files with 21 additions and 14 deletions

View File

@ -16,6 +16,9 @@ extern crate core as std;
// Macros to help create bindings to FFI libraries.
mod macros;
// Basic C type macro modules. // Basic C type macro modules.
mod c_enum; mod c_enum;
mod c_flags; mod c_flags;
@ -24,15 +27,13 @@ mod c_types;
// Raw platform data retrieval. // Raw platform data retrieval.
mod raw; mod raw;
// Macros to help create bindings to FFI libraries.
mod macros;
#[cfg(feature="use_std")]
pub use self::c_types::{CStr, CString, NullByteError};
pub use self::c_types::{CChar, CUChar}; pub use self::c_types::{CChar, CUChar};
pub use self::c_types::{CShort, CUShort, CInt, CUInt, CLong, CULong}; pub use self::c_types::{CShort, CUShort, CInt, CUInt, CLong, CULong};
pub use self::c_types::{CLongLong, CULongLong, CFloat, CDouble}; pub use self::c_types::{CLongLong, CULongLong, CFloat, CDouble};
pub use self::c_types::{CVoid, CReturnVoid}; pub use self::c_types::{CVoid, CReturnVoid};
#[cfg(feature="use_std")]
pub use self::c_types::{CStr, CString, NullByteError};
pub use self::raw::{AsRaw, AsRawMut, AsRawPtr, AsRawMutPtr, FromRaw, IntoRaw}; pub use self::raw::{AsRaw, AsRawMut, AsRawPtr, AsRawMutPtr, FromRaw, IntoRaw};

View File

@ -5,27 +5,33 @@ macro_rules! external_library
$name: ident: $link: expr => $name: ident: $link: expr =>
{ {
$(statics: $(statics:
{
$($sname: ident: $stype: ty);+; $($sname: ident: $stype: ty);+;
)|* }
)?
$(functions: $(functions:
{
$($fname: ident($($farg: ident: $fargt: ty),*) -> $fret:ty);+; $($fname: ident($($farg: ident: $fargt: ty),*) -> $fret:ty);+;
)|* }
)?
$(varargs: $(varargs:
$($vname: ident($($vargs: ident: $vargst: ty),+) -> $vret: ty);+; {
)|* $($vname: ident($($vargs: ident: $vargst: ty),+) -> $vret:ty);+;
}
)?
} }
} => } =>
{ {
#[link(name=$link)] #[link(name=$link)]
extern "C" extern "C"
{ {
$($(pub static $sname: $stype;)+)* $($(pub static $sname: $stype;)+)?
$($(pub fn $fname($($farg: $fargt),*) -> $fret;)+)* $($(pub fn $fname($($farg: $fargt),*) -> $fret;)+)?
$($(pub fn $vname($(vargs: $vargst),+ , ...) -> $vret;)+)* $($(pub fn $vname($(vargs: $vargst),+ , ...) -> $vret;)+)?
}
} }
};
} }