None maps to Nil ezpz

This commit is contained in:
Quaternions 2024-10-04 19:05:21 -07:00
parent acbb1c8478
commit ba9918f2d5

View File

@ -171,16 +171,17 @@ impl Instance{
}; };
dom(lua,|dom|{ dom(lua,|dom|{
let instance=this.get(dom)?; let instance=this.get(dom)?;
let child=match search_descendants{ Ok(
true=>dom.descendants_of(this.referent()).find(|inst|inst.name==name_str), match search_descendants{
false=>instance.children().iter().filter_map(|&r| true=>dom.descendants_of(this.referent()).find(|inst|inst.name==name_str),
dom.get_by_ref(r) false=>instance.children().iter().filter_map(|&r|
).find(|inst|inst.name==name_str), dom.get_by_ref(r)
}; ).find(|inst|inst.name==name_str),
match child{ }
Some(instance)=>Instance::new(instance.referent()).into_lua(lua), .map(|instance|
None=>mlua::Value::Nil.into_lua(lua), Instance::new(instance.referent())
} )
)
}) })
}; };
methods.add_method("FindFirstChild",ffc); methods.add_method("FindFirstChild",ffc);
@ -224,16 +225,15 @@ impl Instance{
dom(lua,|dom|{ dom(lua,|dom|{
let instance=dereferent.get(dom)?; let instance=dereferent.get(dom)?;
//find a child with a matching name //find a child with a matching name
let maybe_child=instance.children() Ok(
.iter() instance.children()
.find(|&&r| .iter()
dom.get_by_ref(r) .find(|&&r|
.is_some_and(|instance|instance.name==index_str) dom.get_by_ref(r)
); .is_some_and(|instance|instance.name==index_str)
match maybe_child{ )
Some(&referent)=>Instance::new(referent).into_lua(lua), .map(|&referent|Instance::new(referent))
None=>mlua::Value::Nil.into_lua(lua), )
}
}) })
}); });
methods.add_meta_function(mlua::MetaMethod::NewIndex,|lua,(this,index,value):(mlua::AnyUserData,mlua::String,mlua::Value)|{ methods.add_meta_function(mlua::MetaMethod::NewIndex,|lua,(this,index,value):(mlua::AnyUserData,mlua::String,mlua::Value)|{