diff options
author | kyren <kerriganw@gmail.com> | 2018-02-11 16:47:39 -0500 |
---|---|---|
committer | kyren <kerriganw@gmail.com> | 2018-02-11 16:47:39 -0500 |
commit | 7231e95195bad7eee5f049f431151b7d70756569 (patch) | |
tree | 73910e2a0e54af27de27573b55c3d0b75117904c /src | |
parent | ce7e8e61fd9849695527b3c0b04db8f7c7c94db1 (diff) | |
download | mlua-7231e95195bad7eee5f049f431151b7d70756569.zip |
It's far too easy to write 'stack_guard' as opposed to 'stack_err_guard'!
And it will work until something fails! Maybe there should be a test that calls
every possible function that invokes to_lua / from_lua with a type where both
directions fail?
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/userdata.rs | 2 | ||||
-rw-r--r-- | src/userdata.rs | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/src/tests/userdata.rs b/src/tests/userdata.rs index 4af0f6e..4a51000 100644 --- a/src/tests/userdata.rs +++ b/src/tests/userdata.rs @@ -1,4 +1,3 @@ - use std::sync::Arc; use {ExternalError, Function, Lua, MetaMethod, String, UserData, UserDataMethods}; @@ -179,4 +178,5 @@ fn user_value() { let ud = lua.create_userdata(MyUserData).unwrap(); ud.set_user_value("hello").unwrap(); assert_eq!(ud.get_user_value::<String>().unwrap(), "hello"); + assert!(ud.get_user_value::<u32>().is_err()); } diff --git a/src/userdata.rs b/src/userdata.rs index c119911..e10f251 100644 --- a/src/userdata.rs +++ b/src/userdata.rs @@ -406,7 +406,7 @@ impl<'lua> AnyUserData<'lua> { pub fn set_user_value<V: ToLua<'lua>>(&self, v: V) -> Result<()> { let lua = self.0.lua; unsafe { - stack_guard(lua.state, 0, || { + stack_err_guard(lua.state, 0, || { check_stack(lua.state, 2); lua.push_ref(lua.state, &self.0); lua.push_value(lua.state, v.to_lua(lua)?); @@ -423,7 +423,7 @@ impl<'lua> AnyUserData<'lua> { pub fn get_user_value<V: FromLua<'lua>>(&self) -> Result<V> { let lua = self.0.lua; unsafe { - stack_guard(lua.state, 0, || { + stack_err_guard(lua.state, 0, || { check_stack(lua.state, 2); lua.push_ref(lua.state, &self.0); ffi::lua_getuservalue(lua.state, -1); |