roblox_emulator: implement IsAncestorOf & IsDescendantOf

This commit is contained in:
Quaternions 2025-04-22 22:26:46 -07:00
parent 94025b52e2
commit c98f53a151
Signed by: Quaternions
GPG Key ID: D0DF5964F79AC131

@ -250,6 +250,18 @@ impl mlua::UserData for Instance{
Ok(children)
})
);
methods.add_method("IsAncestorOf",|lua,this,descendant:Instance|
dom_mut(lua,|dom|{
let instance=descendant.get(dom)?;
Ok(std::iter::successors(Some(instance),|inst|dom.get_by_ref(inst.parent())).any(|inst|inst.referent()==this.referent))
})
);
methods.add_method("IsDescendantOf",|lua,this,ancestor:Instance|
dom_mut(lua,|dom|{
let instance=this.get(dom)?;
Ok(std::iter::successors(Some(instance),|inst|dom.get_by_ref(inst.parent())).any(|inst|inst.referent()==ancestor.referent))
})
);
fn is_a(lua:&mlua::Lua,this:&Instance,classname:mlua::String)->mlua::Result<bool>{
dom_mut(lua,|dom|{
let instance=this.get(dom)?;