From c47f30054fbbabb2e69c26425dc9601fc8468241 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sat, 5 Oct 2024 20:06:58 -0700 Subject: [PATCH] walk the class tree, return the first function found --- src/runner/instance.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/runner/instance.rs b/src/runner/instance.rs index c2b196d..4f34520 100644 --- a/src/runner/instance.rs +++ b/src/runner/instance.rs @@ -226,25 +226,34 @@ impl mlua::UserData for Instance{ let index_str=&*index.to_str()?; dom_mut(lua,|dom|{ let instance=this.get(dom)?; + let db=rbx_reflection_database::get(); + let class=db.classes.get(instance.class.as_str()).ok_or(mlua::Error::runtime("Class missing"))?; //Find existing property match instance.properties.get(index_str) //Find default value - .or_else(||{ - let db=rbx_reflection_database::get(); - db.classes.get(instance.class.as_str()).and_then(|cd| - db.find_default_property(cd,index_str) - ) - }) + .or_else(||db.find_default_property(class,index_str)) { Some(&rbx_types::Variant::CFrame(cf))=>return Ok(Into::::into(cf).into_lua(lua)), Some(&rbx_types::Variant::Vector3(v))=>return Ok(Into::::into(v).into_lua(lua)), _=>(), } //find a function with a matching name - if let Some(ret)=class_functions_mut(lua,|cf| - cf.get_or_create_class_function(lua,instance.class.as_str(),index_str) - )?{ - return Ok(ret.into_lua(lua)); + if let Some(function)=class_functions_mut(lua,|cf|{ + let mut iter=SuperClassIter{ + database:db, + descriptor:Some(class), + }; + Ok(loop{ + match iter.next(){ + Some(class)=>match cf.get_or_create_class_function(lua,&class.name,index_str)?{ + Some(function)=>break Some(function), + None=>(), + }, + None=>break None, + } + }) + })?{ + return Ok(function.into_lua(lua)); } //find a child with a matching name Ok(