roblox_emulator: implement IsAncestorOf & IsDescendantOf
This commit is contained in:
parent
94025b52e2
commit
c98f53a151
@ -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)?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user