diff --git a/lib/roblox_emulator/src/runner/instance/instance.rs b/lib/roblox_emulator/src/runner/instance/instance.rs index 809434d..7f0de1d 100644 --- a/lib/roblox_emulator/src/runner/instance/instance.rs +++ b/lib/roblox_emulator/src/runner/instance/instance.rs @@ -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)?;