diff options
author | kyren <kerriganw@gmail.com> | 2017-06-25 04:25:48 -0400 |
---|---|---|
committer | kyren <kerriganw@gmail.com> | 2017-06-25 04:25:48 -0400 |
commit | bf9bf849c2a03768eb9b9609893ea3a75c8d2bcd (patch) | |
tree | b01fc4c9098b90e8f3f5d1a731fe0ffda6a28047 /src/util.rs | |
parent | 8548fbd263cdda24b941dad583633cbf323e7b5c (diff) | |
download | mlua-bf9bf849c2a03768eb9b9609893ea3a75c8d2bcd.zip |
Simplification of error types
The multi-level error types were a mistake. Probably should have waited on the
cargo version bump, oh well.
Diffstat (limited to 'src/util.rs')
-rw-r--r-- | src/util.rs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/util.rs b/src/util.rs index 99dbb08..a02f574 100644 --- a/src/util.rs +++ b/src/util.rs @@ -8,7 +8,7 @@ use std::os::raw::{c_char, c_int, c_void}; use std::panic::{catch_unwind, resume_unwind, UnwindSafe}; use ffi; -use error::{LuaResult, LuaSyntaxError, LuaUserDataError, LuaError}; +use error::{LuaResult, LuaError}; macro_rules! cstr { ($s:expr) => ( @@ -149,9 +149,9 @@ pub unsafe fn handle_error(state: *mut ffi::lua_State, err: c_int) -> LuaResult< // This seems terrible, but as far as I can tell, this is exactly what the stock lua // repl does. if err_string.ends_with("<eof>") { - LuaSyntaxError::IncompleteStatement(err_string).into() + LuaError::IncompleteStatement(err_string) } else { - LuaSyntaxError::Syntax(err_string).into() + LuaError::SyntaxError(err_string) } } ffi::LUA_ERRERR => LuaError::ErrorError(err_string), @@ -343,17 +343,19 @@ pub struct WrappedPanic(pub Option<Box<Any + Send>>); // Pushes a WrappedError::Error to the top of the stack pub unsafe fn push_wrapped_error(state: *mut ffi::lua_State, err: LuaError) { unsafe extern "C" fn error_tostring(state: *mut ffi::lua_State) -> c_int { - callback_error(state, || { - if !is_wrapped_error(state, -1) { - return Err(LuaUserDataError::TypeMismatch.into()); - } - + callback_error(state, || if is_wrapped_error(state, -1) { let userdata = ffi::lua_touserdata(state, -1); let error = &*(userdata as *const WrappedError); push_string(state, &error.0.to_string()); ffi::lua_remove(state, -2); Ok(1) + + } else { + Err(LuaError::FromLuaConversionError( + "internal error: userdata mismatch in LuaError metamethod" + .to_owned(), + )) }) } |