Skip to content

Commit 98339c5

Browse files
committed
Update userdata tests
1 parent 2331995 commit 98339c5

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

src/userdata.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::string::String;
2121
use crate::table::{Table, TablePairs};
2222
use crate::traits::{FromLua, FromLuaMulti, IntoLua, IntoLuaMulti};
2323
use crate::types::{MaybeSend, ValueRef};
24-
use crate::util::{check_stack, get_userdata, take_userdata, StackGuard};
24+
use crate::util::{check_stack, get_userdata, push_string, take_userdata, StackGuard};
2525
use crate::value::Value;
2626

2727
// Re-export for convenience
@@ -809,13 +809,10 @@ impl AnyUserData {
809809
lua.push_userdata_ref(&self.0)?;
810810

811811
// Multiple (extra) user values are emulated by storing them in a table
812-
protect_lua!(state, 1, 1, |state| {
813-
if ffi::lua_getuservalue(state, -1) != ffi::LUA_TTABLE {
814-
ffi::lua_pushnil(state);
815-
return;
816-
}
817-
ffi::lua_rawgeti(state, -1, n as ffi::lua_Integer);
818-
})?;
812+
if ffi::lua_getuservalue(state, -1) != ffi::LUA_TTABLE {
813+
return V::from_lua(Value::Nil, lua.lua());
814+
}
815+
ffi::lua_rawgeti(state, -1, n as ffi::lua_Integer);
819816

820817
V::from_lua(lua.pop_value(), lua.lua())
821818
}
@@ -873,16 +870,13 @@ impl AnyUserData {
873870
lua.push_userdata_ref(&self.0)?;
874871

875872
// Multiple (extra) user values are emulated by storing them in a table
876-
protect_lua!(state, 1, 1, |state| {
877-
if ffi::lua_getuservalue(state, -1) != ffi::LUA_TTABLE {
878-
ffi::lua_pushnil(state);
879-
return;
880-
}
881-
ffi::lua_pushlstring(state, name.as_ptr() as *const c_char, name.len());
882-
ffi::lua_rawget(state, -2);
883-
})?;
873+
if ffi::lua_getuservalue(state, -1) != ffi::LUA_TTABLE {
874+
return V::from_lua(Value::Nil, lua.lua());
875+
}
876+
push_string(state, name.as_bytes(), !lua.unlikely_memory_error())?;
877+
ffi::lua_rawget(state, -2);
884878

885-
V::from_lua(lua.pop_value(), lua.lua())
879+
V::from_stack(-1, &lua)
886880
}
887881
}
888882

src/userdata/lock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub(crate) trait UserDataLock {
1111
pub(crate) use lock_impl::RawLock;
1212

1313
#[cfg(not(feature = "send"))]
14+
#[cfg(not(tarpaulin_include))]
1415
mod lock_impl {
1516
use std::cell::Cell;
1617

tests/userdata.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ fn test_user_values() -> Result<()> {
418418
assert!(ud.nth_user_value::<Value>(65536).is_err());
419419

420420
// Named user values
421+
let ud = lua.create_userdata(MyUserData)?;
421422
ud.set_named_user_value("name", "alex")?;
422423
ud.set_named_user_value("age", 10)?;
423424

0 commit comments

Comments
 (0)