implement Instance.__index
This commit is contained in:
parent
40655cdf44
commit
e67f0f0889
@ -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:?}");
|
||||
|
Loading…
Reference in New Issue
Block a user