diff --git a/src/lua.rs b/src/lua.rs index 455a4b4..0f97cd7 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -51,8 +51,7 @@ impl Drop for Lua { if cfg!(test) { let top = ffi::lua_gettop(self.state); if top != 0 { - eprintln!("Lua stack leak detected, stack top is {}", top); - process::abort() + lua_internal_abort!("Lua stack leak detected, stack top is {}", top); } } @@ -894,8 +893,7 @@ impl Lua { // not really a huge loss. Importantly, this allows us to turn off the gc, and // then know that calling Lua API functions marked as 'm' will not result in a // 'longjmp' error while the gc is off. - eprintln!("Out of memory in Lua allocation, aborting!"); - process::abort() + lua_abort!("out of memory in Lua allocation, aborting!"); } else { p as *mut c_void } diff --git a/src/macros.rs b/src/macros.rs index 929e2d7..61ec299 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -38,6 +38,22 @@ macro_rules! lua_assert { }; } +macro_rules! lua_abort { + ($msg:expr) => { + { + eprintln!($msg); + ::std::process::abort() + } + }; + + ($msg:expr, $($arg:tt)+) => { + { + eprintln!($msg, $($arg)+); + ::std::process::abort() + } + }; +} + macro_rules! lua_internal_panic { ($state:expr, $msg:expr) => { lua_panic!($state, concat!("rlua internal error: ", $msg)); @@ -57,3 +73,17 @@ macro_rules! lua_internal_assert { lua_assert!($state, $cond, concat!("rlua internal error: ", $msg), $($arg)+); }; } + +macro_rules! lua_internal_abort { + ($msg:expr) => { + { + lua_abort!(concat!("rlua internal error: ", $msg)); + } + }; + + ($msg:expr, $($arg:tt)+) => { + { + lua_abort!(concat!("rlua internal error, aborting!: ", $msg), $($arg)+); + } + }; +} diff --git a/src/util.rs b/src/util.rs index 0020d52..d89b92b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -226,8 +226,7 @@ pub unsafe fn pop_error(state: *mut ffi::lua_State, err_code: c_int) -> Error { ffi::LUA_ERRMEM => { // This should be impossible, as we set the lua allocator to one that aborts // instead of failing. - eprintln!("impossible Lua allocation error, aborting!"); - process::abort() + lua_internal_abort!("impossible Lua allocation error, aborting!") } ffi::LUA_ERRGCMM => Error::GarbageCollectorError(err_string), _ => lua_internal_panic!(state, "unrecognized lua error code"),