mirror of
https://github.com/mlua-rs/mlua
synced 2026-06-08 16:05:43 +00:00
AnyUserData::is_proxy (#666)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user