diff --git a/src/runner/instance.rs b/src/runner/instance.rs index 0dad951..ffb950c 100644 --- a/src/runner/instance.rs +++ b/src/runner/instance.rs @@ -152,6 +152,23 @@ impl Instance{ Ok(crate::context::class_is_a(instance.class.as_str(),classname.to_str()?)) }) ); + methods.add_meta_function(mlua::MetaMethod::Index,|lua,(this,index):(Self,mlua::String)|{ + let index_str=index.to_str()?; + dom(lua,|dom|{ + let instance=this.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), + } + }) + }); methods.add_meta_function(mlua::MetaMethod::NewIndex,|lua,(this,index,value):(Self,mlua::String,mlua::Value)| dom(lua,|dom|{ //println!("__newindex t={this:?} i={index:?} v={value:?}");