roblox_emulator: implement EnumItem.__eq

This commit is contained in:
2025-04-23 02:00:09 -07:00
parent 5b5f356863
commit 84db6503f9

@ -23,6 +23,17 @@ impl From<EnumItem<'_>> for rbx_types::Enum{
rbx_types::Enum::from_u32(e.value) rbx_types::Enum::from_u32(e.value)
} }
} }
impl PartialEq for EnumItem<'_>{
fn eq(&self,other:&EnumItem<'_>)->bool{
self.value==other.value&&{
// if both names are known, they must match, otherwise whatever
match (self.name,other.name){
(Some(lhs),Some(rhs))=>lhs==rhs,
_=>true,
}
}
}
}
#[derive(Clone,Copy)] #[derive(Clone,Copy)]
pub struct Enums; pub struct Enums;
@ -69,7 +80,10 @@ impl mlua::UserData for EnumItem<'_>{
fields.add_field_method_get("Name",|_,this|Ok(this.name)); fields.add_field_method_get("Name",|_,this|Ok(this.name));
fields.add_field_method_get("Value",|_,this|Ok(this.value)); fields.add_field_method_get("Value",|_,this|Ok(this.value));
} }
fn add_methods<M:mlua::UserDataMethods<Self>>(_methods:&mut M){ fn add_methods<M:mlua::UserDataMethods<Self>>(methods:&mut M){
methods.add_meta_function(mlua::MetaMethod::Eq,|_,(lhs,rhs):(EnumItem<'_>,EnumItem<'_>)|{
Ok(lhs==rhs)
});
} }
} }
type_from_lua_userdata_lua_lifetime!(EnumItem); type_from_lua_userdata_lua_lifetime!(EnumItem);