Instance FindFirstChild + WaitForChild (no difference in implementation)
This commit is contained in:
parent
cb5b842276
commit
0148476648
@ -158,6 +158,29 @@ impl Instance{
|
|||||||
Ok(children)
|
Ok(children)
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
let ffc=|lua,this:&T,(name,search_descendants):(mlua::String,mlua::Value)|{
|
||||||
|
let name_str=name.to_str()?;
|
||||||
|
let search_descendants=match search_descendants{
|
||||||
|
mlua::Value::Nil=>false,
|
||||||
|
mlua::Value::Boolean(b)=>b,
|
||||||
|
_=>Err(mlua::Error::runtime("Invalid argument #3 bool expected"))?,
|
||||||
|
};
|
||||||
|
dom(lua,|dom|{
|
||||||
|
let instance=this.get(dom)?;
|
||||||
|
let child=match search_descendants{
|
||||||
|
true=>dom.descendants_of(this.referent()).find(|inst|inst.name==name_str),
|
||||||
|
false=>instance.children().iter().filter_map(|&r|
|
||||||
|
dom.get_by_ref(r)
|
||||||
|
).find(|inst|inst.name==name_str),
|
||||||
|
};
|
||||||
|
match child{
|
||||||
|
Some(instance)=>Instance::new(instance.referent()).into_lua(lua),
|
||||||
|
None=>mlua::Value::Nil.into_lua(lua),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
methods.add_method("FindFirstChild",ffc);
|
||||||
|
methods.add_method("WaitForChild",ffc);
|
||||||
methods.add_method("GetDescendants",|lua,this,_:()|
|
methods.add_method("GetDescendants",|lua,this,_:()|
|
||||||
dom(lua,|dom|{
|
dom(lua,|dom|{
|
||||||
let children:Vec<_>=dom
|
let children:Vec<_>=dom
|
||||||
|
Loading…
Reference in New Issue
Block a user