split macros into their own file
This commit is contained in:
parent
8a7e03978b
commit
fa1703d3d1
|
@ -45,6 +45,7 @@ extern crate libc;
|
|||
mod ffi;
|
||||
mod error;
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
mod util;
|
||||
mod protected;
|
||||
mod types;
|
||||
|
|
|
@ -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)+);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
54
src/util.rs
54
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) {
|
||||
|
|
Loading…
Reference in New Issue