Skip to content

Commit ee9232e

Browse files
authored
AnyUserData::is_proxy (#666)
1 parent da52659 commit ee9232e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/userdata.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,14 @@ impl AnyUserData {
679679
matches!(type_id, Some(type_id) if type_id == TypeId::of::<T>())
680680
}
681681

682+
/// Checks whether the type of this userdata is a [proxy object] for `T`.
683+
///
684+
/// [proxy object]: crate::Lua::create_proxy
685+
#[inline]
686+
pub fn is_proxy<T: 'static>(&self) -> bool {
687+
self.is::<UserDataProxy<T>>()
688+
}
689+
682690
/// Borrow this userdata immutably if it is of type `T`.
683691
///
684692
/// # Errors

tests/userdata.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,9 @@ fn test_userdata_proxy() -> Result<()> {
731731
let globals = lua.globals();
732732
globals.set("MyUserData", lua.create_proxy::<MyUserData>()?)?;
733733

734+
assert!(!globals.get::<AnyUserData>("MyUserData")?.is_proxy::<()>());
735+
assert!(globals.get::<AnyUserData>("MyUserData")?.is_proxy::<MyUserData>());
736+
734737
lua.load(
735738
r#"
736739
assert(MyUserData.static_field == 123)

0 commit comments

Comments
 (0)