diff --git a/src/runner/instance.rs b/src/runner/instance.rs index 3e79efd..b219885 100644 --- a/src/runner/instance.rs +++ b/src/runner/instance.rs @@ -158,6 +158,29 @@ impl Instance{ 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,_:()| dom(lua,|dom|{ let children:Vec<_>=dom