Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/userdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/userdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading