walk the class tree, return the first function found

This commit is contained in:
Quaternions 2024-10-05 20:06:58 -07:00
parent c96d9b7aef
commit c47f30054f

View File

@ -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::<super::cframe::CFrame>::into(cf).into_lua(lua)),
Some(&rbx_types::Variant::Vector3(v))=>return Ok(Into::<super::vector3::Vector3>::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(