From 69754bd8301ba0686383b5a7b67976ab720627f1 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sun, 19 Mar 2023 13:36:33 +0100 Subject: [PATCH] Implement equality for roblox instances --- packages/lib-roblox/src/instance/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/lib-roblox/src/instance/mod.rs b/packages/lib-roblox/src/instance/mod.rs index 4c1994f..6549aa9 100644 --- a/packages/lib-roblox/src/instance/mod.rs +++ b/packages/lib-roblox/src/instance/mod.rs @@ -13,7 +13,7 @@ use crate::{ datatypes::{ conversion::{DomValueToLua, LuaToDomValue}, types::EnumItem, - userdata_impl_to_string, + userdata_impl_eq, userdata_impl_to_string, }, shared::instance::{ class_exists, class_is_a, find_property_enum, find_property_type, property_is_enum, @@ -309,6 +309,7 @@ impl Instance { impl LuaUserData for Instance { 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::Eq, userdata_impl_eq); /* Getting a value does the following: @@ -485,3 +486,9 @@ impl fmt::Display for Instance { write!(f, "{}", self.get_name()) } } + +impl PartialEq for Instance { + fn eq(&self, other: &Self) -> bool { + self.dom_ref == other.dom_ref + } +}