From fa1703d3d1d1c7541e829f0d193860c2281f95f2 Mon Sep 17 00:00:00 2001 From: kyren Date: Sat, 2 Dec 2017 17:04:33 -0500 Subject: [PATCH] split macros into their own file --- src/lib.rs | 1 + src/macros.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/util.rs | 54 --------------------------------------------------- 3 files changed, 55 insertions(+), 54 deletions(-) create mode 100644 src/macros.rs diff --git a/src/lib.rs b/src/lib.rs index b704fee..afc81ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,6 +45,7 @@ extern crate libc; mod ffi; mod error; #[macro_use] +mod macros; mod util; mod protected; mod types; diff --git a/src/macros.rs b/src/macros.rs new file mode 100644 index 0000000..13130ac --- /dev/null +++ b/src/macros.rs @@ -0,0 +1,54 @@ +macro_rules! cstr { + ($s:expr) => ( + concat!($s, "\0") as *const str as *const [c_char] as *const c_char + ); +} + +// A panic that clears the given lua stack before panicking +macro_rules! lua_panic { + ($state:expr) => { + { + $crate::ffi::lua_settor($state, 0); + panic!("rlua internal error"); + } + }; + + ($state:expr, $msg:expr) => { + { + $crate::ffi::lua_settop($state, 0); + panic!(concat!("rlua: ", $msg)); + } + }; + + ($state:expr, $fmt:expr, $($arg:tt)+) => { + { + $crate::ffi::lua_settop($state, 0); + panic!(concat!("rlua: ", $fmt), $($arg)+); + } + }; +} + +// An assert that clears the given lua stack before panicking +macro_rules! lua_assert { + ($state:expr, $cond:expr) => { + if !$cond { + $crate::ffi::lua_settop($state, 0); + panic!("rlua internal error"); + } + }; + + ($state:expr, $cond:expr, $msg:expr) => { + if !$cond { + $crate::ffi::lua_settop($state, 0); + panic!(concat!("rlua: ", $msg)); + } + }; + + ($state:expr, $cond:expr, $fmt:expr, $($arg:tt)+) => { + if !$cond { + $crate::ffi::lua_settop($state, 0); + panic!(concat!("rlua: ", $fmt), $($arg)+); + } + }; +} + diff --git a/src/util.rs b/src/util.rs index 769024c..8641957 100644 --- a/src/util.rs +++ b/src/util.rs @@ -10,60 +10,6 @@ use std::panic::{catch_unwind, resume_unwind, UnwindSafe}; use ffi; use error::{Error, Result}; -macro_rules! cstr { - ($s:expr) => ( - concat!($s, "\0") as *const str as *const [c_char] as *const c_char - ); -} - -// A panic that clears the given lua stack before panicking -macro_rules! lua_panic { - ($state:expr) => { - { - $crate::ffi::lua_settor($state, 0); - panic!("rlua internal error"); - } - }; - - ($state:expr, $msg:expr) => { - { - $crate::ffi::lua_settop($state, 0); - panic!(concat!("rlua: ", $msg)); - } - }; - - ($state:expr, $fmt:expr, $($arg:tt)+) => { - { - $crate::ffi::lua_settop($state, 0); - panic!(concat!("rlua: ", $fmt), $($arg)+); - } - }; -} - -// An assert that clears the given lua stack before panicking -macro_rules! lua_assert { - ($state:expr, $cond:expr) => { - if !$cond { - $crate::ffi::lua_settop($state, 0); - panic!("rlua internal error"); - } - }; - - ($state:expr, $cond:expr, $msg:expr) => { - if !$cond { - $crate::ffi::lua_settop($state, 0); - panic!(concat!("rlua: ", $msg)); - } - }; - - ($state:expr, $cond:expr, $fmt:expr, $($arg:tt)+) => { - if !$cond { - $crate::ffi::lua_settop($state, 0); - panic!(concat!("rlua: ", $fmt), $($arg)+); - } - }; -} - // Checks that Lua has enough free stack space for future stack operations. // On failure, this will clear the stack and panic. pub unsafe fn check_stack(state: *mut ffi::lua_State, amount: c_int) {