From ba9918f2d557c42dfdfea248a12f8f5ff9f51bd3 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 4 Oct 2024 19:05:21 -0700 Subject: [PATCH] None maps to Nil ezpz --- src/runner/instance.rs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/runner/instance.rs b/src/runner/instance.rs index 5a229b0..ed695ad 100644 --- a/src/runner/instance.rs +++ b/src/runner/instance.rs @@ -171,16 +171,17 @@ impl Instance{ }; 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), - } + Ok( + 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), + } + .map(|instance| + Instance::new(instance.referent()) + ) + ) }) }; methods.add_method("FindFirstChild",ffc); @@ -224,16 +225,15 @@ impl Instance{ dom(lua,|dom|{ let instance=dereferent.get(dom)?; //find a child with a matching name - let maybe_child=instance.children() - .iter() - .find(|&&r| - dom.get_by_ref(r) - .is_some_and(|instance|instance.name==index_str) - ); - match maybe_child{ - Some(&referent)=>Instance::new(referent).into_lua(lua), - None=>mlua::Value::Nil.into_lua(lua), - } + Ok( + instance.children() + .iter() + .find(|&&r| + dom.get_by_ref(r) + .is_some_and(|instance|instance.name==index_str) + ) + .map(|&referent|Instance::new(referent)) + ) }) }); methods.add_meta_function(mlua::MetaMethod::NewIndex,|lua,(this,index,value):(mlua::AnyUserData,mlua::String,mlua::Value)|{