From d272ac242bf996a920c7921fd6806de99fe6150d Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 3 Oct 2024 19:14:58 -0700 Subject: [PATCH] sneak past type issues --- src/runner/instance.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/runner/instance.rs b/src/runner/instance.rs index ffb950c..cef224f 100644 --- a/src/runner/instance.rs +++ b/src/runner/instance.rs @@ -33,6 +33,11 @@ fn get_full_name(dom:&rbx_dom_weak::WeakDom,instance:&rbx_dom_weak::Instance)->S struct Dereferent(Ref); impl mlua::UserData for Dereferent{} type_from_lua_userdata!(Dereferent); +impl Referent for Dereferent{ + fn referent(&self)->Ref{ + self.0 + } +} trait Referent{ fn referent(&self)->Ref; @@ -152,10 +157,11 @@ 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)|{ + methods.add_meta_function(mlua::MetaMethod::Index,|lua,(this,index):(mlua::AnyUserData,mlua::String)|{ let index_str=index.to_str()?; + let dereferent:Dereferent=mlua::AnyUserDataExt::get(&this,"Referent")?; dom(lua,|dom|{ - let instance=this.get(dom)?; + let instance=dereferent.get(dom)?; //find a child with a matching name let maybe_child=instance.children() .iter() @@ -169,10 +175,11 @@ impl Instance{ } }) }); - methods.add_meta_function(mlua::MetaMethod::NewIndex,|lua,(this,index,value):(Self,mlua::String,mlua::Value)| + methods.add_meta_function(mlua::MetaMethod::NewIndex,|lua,(this,index,value):(mlua::AnyUserData,mlua::String,mlua::Value)|{ + let dereferent:Dereferent=mlua::AnyUserDataExt::get(&this,"Referent")?; dom(lua,|dom|{ - //println!("__newindex t={this:?} i={index:?} v={value:?}"); - let instance=this.get_mut(dom)?; + let instance=dereferent.get_mut(dom)?; + //println!("__newindex t={} i={index:?} v={value:?}",instance.name); let index_str=index.to_str()?; let db=rbx_reflection_database::get(); let class=db.classes.get(instance.class.as_str()).ok_or(mlua::Error::runtime("Class missing"))?; @@ -198,7 +205,7 @@ impl Instance{ } Ok(()) }) - ); + }); } }