Add ExpiredUserData error and avoid what was previously a panic

Also make sure that panic messages clearly state that they are internal errors,
so people report them as a bug.  Since the only panics left are all internal
errors, just move the internal error message into the panic / assert macros.
This commit is contained in:
kyren
2017-12-04 02:46:57 -05:00
parent 80a98ef29c
commit 66a4e9a8e7
7 changed files with 71 additions and 36 deletions
+2 -2
View File
@@ -567,7 +567,7 @@ impl Lua {
&LUA_USERDATA_REGISTRY_KEY as *const u8 as *mut c_void,
);
ffi::lua_gettable(self.state, ffi::LUA_REGISTRYINDEX);
let registered_userdata = get_userdata::<HashMap<TypeId, c_int>>(self.state, -1);
let registered_userdata = get_userdata::<HashMap<TypeId, c_int>>(self.state, -1)?;
ffi::lua_pop(self.state, 1);
if let Some(table_id) = (*registered_userdata).get(&TypeId::of::<T>()) {
@@ -798,7 +798,7 @@ impl Lua {
ephemeral: true,
};
let func = get_userdata::<RefCell<Callback>>(state, ffi::lua_upvalueindex(1));
let func = get_userdata::<RefCell<Callback>>(state, ffi::lua_upvalueindex(1))?;
let mut func = (*func)
.try_borrow_mut()
.map_err(|_| Error::RecursiveCallbackError)?;