summaryrefslogtreecommitdiff
path: root/src/macros.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/macros.rs')
-rw-r--r--src/macros.rs76
1 files changed, 45 insertions, 31 deletions
diff --git a/src/macros.rs b/src/macros.rs
index b37722a..8259c0d 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -1,3 +1,13 @@
+macro_rules! bug_msg {
+ ($arg:expr) => {
+ concat!(
+ "rlua internal error: ",
+ $arg,
+ " (this is a bug, please file an issue)"
+ )
+ };
+}
+
macro_rules! cstr {
($s:expr) => {
concat!($s, "\0") as *const str as *const [::std::os::raw::c_char]
@@ -5,62 +15,66 @@ macro_rules! cstr {
};
}
-macro_rules! abort {
+macro_rules! rlua_panic {
($msg:expr) => {
- {
- eprintln!($msg);
- ::std::process::abort()
- }
+ panic!(bug_msg!($msg));
};
- ($msg:expr, $($arg:tt)+) => {
- {
- eprintln!($msg, $($arg)+);
- ::std::process::abort()
- }
+ ($msg:expr,) => {
+ rlua_panic!($msg);
};
-}
-macro_rules! rlua_panic {
- ($msg:expr) => {
- panic!(concat!("rlua internal error: ", $msg));
+ ($msg:expr, $($arg:expr),+) => {
+ panic!(bug_msg!($msg), $($arg),+);
};
- ($msg:expr, $($arg:tt)+) => {
- panic!(concat!("rlua internal error: ", $msg), $($arg)+);
+ ($msg:expr, $($arg:expr),+,) => {
+ rlua_panic!($msg, $($arg),+);
};
}
macro_rules! rlua_assert {
($cond:expr, $msg:expr) => {
- assert!($cond, concat!("rlua internal error: ", $msg));
+ assert!($cond, bug_msg!($msg));
+ };
+
+ ($cond:expr, $msg:expr,) => {
+ rlua_assert!($cond, $msg);
+ };
+
+ ($cond:expr, $msg:expr, $($arg:expr),+) => {
+ assert!($cond, bug_msg!($msg), $($arg),+);
};
- ($cond:expr, $msg:expr, $($arg:tt)+) => {
- assert!($cond, concat!("rlua internal error: ", $msg), $($arg)+);
+ ($cond:expr, $msg:expr, $($arg:expr),+,) => {
+ rlua_assert!($cond, $msg, $($arg),+);
};
}
macro_rules! rlua_debug_assert {
($cond:expr, $msg:expr) => {
- debug_assert!($cond, concat!("rlua internal error: ", $msg));
+ debug_assert!($cond, bug_msg!($msg));
+ };
+
+ ($cond:expr, $msg:expr,) => {
+ rlua_debug_assert!($cond, $msg);
+ };
+
+ ($cond:expr, $msg:expr, $($arg:expr),+) => {
+ debug_assert!($cond, bug_msg!($msg), $($arg),+);
};
- ($cond:expr, $msg:expr, $($arg:tt)+) => {
- debug_assert!($cond, concat!("rlua internal error: ", $msg), $($arg)+);
+ ($cond:expr, $msg:expr, $($arg:expr),+,) => {
+ rlua_debug_assert!($cond, $msg, $($arg),+);
};
}
-macro_rules! rlua_abort {
- ($msg:expr) => {
- {
- abort!(concat!("rlua internal error: ", $msg));
- }
+macro_rules! rlua_expect {
+ ($res:expr, $msg:expr) => {
+ $res.expect(bug_msg!($msg))
};
- ($msg:expr, $($arg:tt)+) => {
- {
- abort!(concat!("rlua internal error, aborting!: ", $msg), $($arg)+);
- }
+ ($res:expr, $msg:expr,) => {
+ rlua_expect!($res, $msg)
};
}