From ee9232eda1e26e6beaf68c6b1cc355604d2bf8ea Mon Sep 17 00:00:00 2001 From: psentee <135014396+psentee@users.noreply.github.com> Date: Tue, 13 Jan 2026 16:08:38 +0100 Subject: [PATCH] AnyUserData::is_proxy (#666) --- src/userdata.rs | 8 ++++++++ tests/userdata.rs | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/userdata.rs b/src/userdata.rs index ef32048..86e05f6 100644 --- a/src/userdata.rs +++ b/src/userdata.rs @@ -679,6 +679,14 @@ impl AnyUserData { matches!(type_id, Some(type_id) if type_id == TypeId::of::()) } + /// Checks whether the type of this userdata is a [proxy object] for `T`. + /// + /// [proxy object]: crate::Lua::create_proxy + #[inline] + pub fn is_proxy(&self) -> bool { + self.is::>() + } + /// Borrow this userdata immutably if it is of type `T`. /// /// # Errors diff --git a/tests/userdata.rs b/tests/userdata.rs index 6f10869..a84eb52 100644 --- a/tests/userdata.rs +++ b/tests/userdata.rs @@ -731,6 +731,9 @@ fn test_userdata_proxy() -> Result<()> { let globals = lua.globals(); globals.set("MyUserData", lua.create_proxy::()?)?; + assert!(!globals.get::("MyUserData")?.is_proxy::<()>()); + assert!(globals.get::("MyUserData")?.is_proxy::()); + lua.load( r#" assert(MyUserData.static_field == 123)