AnyUserData::is_proxy (#666)

This commit is contained in:
psentee
2026-01-13 16:08:38 +01:00
committed by GitHub
parent da526595bb
commit ee9232eda1
2 changed files with 11 additions and 0 deletions
+8
View File
@@ -679,6 +679,14 @@ impl AnyUserData {
matches!(type_id, Some(type_id) if type_id == TypeId::of::<T>())
}
/// Checks whether the type of this userdata is a [proxy object] for `T`.
///
/// [proxy object]: crate::Lua::create_proxy
#[inline]
pub fn is_proxy<T: 'static>(&self) -> bool {
self.is::<UserDataProxy<T>>()
}
/// Borrow this userdata immutably if it is of type `T`.
///
/// # Errors
+3
View File
@@ -731,6 +731,9 @@ fn test_userdata_proxy() -> Result<()> {
let globals = lua.globals();
globals.set("MyUserData", lua.create_proxy::<MyUserData>()?)?;
assert!(!globals.get::<AnyUserData>("MyUserData")?.is_proxy::<()>());
assert!(globals.get::<AnyUserData>("MyUserData")?.is_proxy::<MyUserData>());
lua.load(
r#"
assert(MyUserData.static_field == 123)