From ecb382c0c3633daf43e8946282ffbb23d13b35a2 Mon Sep 17 00:00:00 2001 From: Jason Travis Smith Date: Tue, 25 Jun 2019 02:53:19 -0400 Subject: [PATCH] Added a macro for wrapping C STD lib functions. --- src/macros.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/macros.rs b/src/macros.rs index 5a7c966..380abf4 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,3 +1,37 @@ +#[macro_export] +macro_rules! c_library +{ + { + $(statics: + { + $($sname: ident: $stype: ty);+; + } + )? + + $(functions: + { + $($fname: ident($($farg: ident: $fargt: ty),*) -> $fret:ty);+; + } + )? + + $(varargs: + { + $($vname: ident($($vargs: ident: $vargst: ty),+) -> $vret:ty);+; + } + )? + } => + { + extern "C" + { + $($(pub static $sname: $stype;)+)? + + $($(pub fn $fname($($farg: $fargt),*) -> $fret;)+)? + + $($(pub fn $vname($(vargs: $vargst),+ , ...) -> $vret;)+)? + } + }; +} + #[macro_export] macro_rules! external_library {