diff --git a/src/userdata.rs b/src/userdata.rs index ef320480..86e05f65 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 6f10869d..a84eb526 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)