hack together .Position

This commit is contained in:
Quaternions 2024-10-06 17:14:46 -07:00
parent 3f71ead5f1
commit 5726e70582

View File

@ -253,7 +253,23 @@ impl mlua::UserData for Instance{
Some(&rbx_types::Variant::Ref(val))=>return Instance::new(val).into_lua(lua),
Some(&rbx_types::Variant::CFrame(cf))=>return Into::<super::cframe::CFrame>::into(cf).into_lua(lua),
Some(&rbx_types::Variant::Vector3(v))=>return Into::<super::vector3::Vector3>::into(v).into_lua(lua),
None=>(),
None=>{
//hack to make .Position work
if let Some((property_str,dumb_thing))=match index_str{
"Position"=>Some(("CFrame",|c:&rbx_types::Variant|{
let c=match c{
rbx_types::Variant::CFrame(c)=>c,
_=>return Err(mlua::Error::runtime("Not a CFrame")),
};
Into::<super::vector3::Vector3>::into(c.position).into_lua(lua)
})),
_=>None,
}{
if let Some(thing)=instance.properties.get(property_str).map(dumb_thing){
return thing;
}
}
},
other=>return Err(mlua::Error::runtime(format!("Instance.__index Unsupported property type instance={} index={index_str} value={other:?}",instance.name))),
}
//find a function with a matching name