Implement equality for roblox instances

This commit is contained in:
Filip Tibell 2023-03-19 13:36:33 +01:00
parent 34d6e622b7
commit 69754bd830
No known key found for this signature in database

View file

@ -13,7 +13,7 @@ use crate::{
datatypes::{ datatypes::{
conversion::{DomValueToLua, LuaToDomValue}, conversion::{DomValueToLua, LuaToDomValue},
types::EnumItem, types::EnumItem,
userdata_impl_to_string, userdata_impl_eq, userdata_impl_to_string,
}, },
shared::instance::{ shared::instance::{
class_exists, class_is_a, find_property_enum, find_property_type, property_is_enum, class_exists, class_is_a, find_property_enum, find_property_type, property_is_enum,
@ -309,6 +309,7 @@ impl Instance {
impl LuaUserData for Instance { impl LuaUserData for Instance {
fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) { fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) {
methods.add_meta_method(LuaMetaMethod::ToString, userdata_impl_to_string); methods.add_meta_method(LuaMetaMethod::ToString, userdata_impl_to_string);
methods.add_meta_method(LuaMetaMethod::Eq, userdata_impl_eq);
/* /*
Getting a value does the following: Getting a value does the following:
@ -485,3 +486,9 @@ impl fmt::Display for Instance {
write!(f, "{}", self.get_name()) write!(f, "{}", self.get_name())
} }
} }
impl PartialEq for Instance {
fn eq(&self, other: &Self) -> bool {
self.dom_ref == other.dom_ref
}
}