summaryrefslogtreecommitdiff
path: root/src/util.rs
diff options
context:
space:
mode:
authorkyren <kerriganw@gmail.com>2017-06-25 02:40:09 -0400
committerkyren <kerriganw@gmail.com>2017-06-25 02:40:09 -0400
commit7dba280a4b17a56e3b81bf04cb181d7850c16317 (patch)
treee9c839759a30cbedb3dc14b3cacbacef46cb2235 /src/util.rs
parentcbae1a805a41b78b8dbf9bf950a790cccaabb3cf (diff)
downloadmlua-7dba280a4b17a56e3b81bf04cb181d7850c16317.zip
Tests for LuaError conversion, Important pcall / xpcall bugfixes.
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/util.rs b/src/util.rs
index 207b74d..99dbb08 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -286,8 +286,14 @@ pub unsafe extern "C" fn safe_pcall(state: *mut ffi::lua_State) -> c_int {
if is_wrapped_panic(state, -1) {
ffi::lua_error(state);
}
+ ffi::lua_pushboolean(state, 0);
+ ffi::lua_insert(state, -2);
+ 2
+ } else {
+ ffi::lua_pushboolean(state, 1);
+ ffi::lua_insert(state, 1);
+ ffi::lua_gettop(state)
}
- ffi::lua_gettop(state)
}
// A variant of xpcall that does not allow lua to catch panic errors from callback_error
@@ -313,8 +319,14 @@ pub unsafe extern "C" fn safe_xpcall(state: *mut ffi::lua_State) -> c_int {
if is_wrapped_panic(state, -1) {
ffi::lua_error(state);
}
+ ffi::lua_pushboolean(state, 0);
+ ffi::lua_insert(state, -2);
+ 2
+ } else {
+ ffi::lua_pushboolean(state, 1);
+ ffi::lua_insert(state, 1);
+ ffi::lua_gettop(state)
}
- res
}
/// Does not call checkstack, uses 1 stack space
@@ -427,7 +439,9 @@ pub unsafe fn pop_wrapped_error(state: *mut ffi::lua_State) -> Option<LuaError>
} else {
let userdata = ffi::lua_touserdata(state, -1);
let err = &*(userdata as *const WrappedError);
- Some(err.0.clone())
+ let err = err.0.clone();
+ ffi::lua_pop(state, 1);
+ Some(err)
}
}