|
|
|
|
@@ -267,11 +267,12 @@ impl mlua::UserData for Instance{
|
|
|
|
|
database:db,
|
|
|
|
|
descriptor:Some(class),
|
|
|
|
|
};
|
|
|
|
|
iter.find_map(|class|{
|
|
|
|
|
let mut class_methods=cf.get_or_create_class_methods(&class.name)?;
|
|
|
|
|
class_methods.get_or_create_function(lua,index_str)
|
|
|
|
|
.transpose()
|
|
|
|
|
}).transpose()
|
|
|
|
|
iter.find_map(|class|
|
|
|
|
|
cf.get_or_create_class_methods(&class.name)
|
|
|
|
|
.and_then(|mut class_methods|
|
|
|
|
|
class_methods.get_or_create_function(lua,index_str).transpose()
|
|
|
|
|
)
|
|
|
|
|
).transpose()
|
|
|
|
|
})?{
|
|
|
|
|
return function.into_lua(lua);
|
|
|
|
|
}
|
|
|
|
|
@@ -295,7 +296,7 @@ impl mlua::UserData for Instance{
|
|
|
|
|
let property=iter.find_map(|cls|cls.properties.get(index_str)).ok_or(mlua::Error::runtime(format!("Property '{index_str}' missing on class '{}'",class.name)))?;
|
|
|
|
|
match &property.data_type{
|
|
|
|
|
rbx_reflection::DataType::Value(rbx_types::VariantType::Vector3)=>{
|
|
|
|
|
let typed_value:Vector3=*value.as_userdata().ok_or(mlua::Error::runtime("Expected Userdata"))?.borrow()?;
|
|
|
|
|
let typed_value:Vector3=value.as_userdata().ok_or(mlua::Error::runtime("Expected Userdata"))?.take()?;
|
|
|
|
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Vector3(typed_value.into()));
|
|
|
|
|
},
|
|
|
|
|
rbx_reflection::DataType::Value(rbx_types::VariantType::Float32)=>{
|
|
|
|
|
@@ -311,7 +312,7 @@ impl mlua::UserData for Instance{
|
|
|
|
|
Ok(rbx_types::Enum::from_u32(*e.items.get(&*s.to_str()?).ok_or(mlua::Error::runtime("Invalid enum item"))?))
|
|
|
|
|
},
|
|
|
|
|
mlua::Value::UserData(any_user_data)=>{
|
|
|
|
|
let e:super::r#enum::Enum=*any_user_data.borrow()?;
|
|
|
|
|
let e:super::r#enum::Enum=any_user_data.take()?;
|
|
|
|
|
Ok(e.into())
|
|
|
|
|
},
|
|
|
|
|
_=>Err(mlua::Error::runtime("Expected Enum")),
|
|
|
|
|
@@ -319,7 +320,7 @@ impl mlua::UserData for Instance{
|
|
|
|
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Enum(typed_value));
|
|
|
|
|
},
|
|
|
|
|
rbx_reflection::DataType::Value(rbx_types::VariantType::Color3)=>{
|
|
|
|
|
let typed_value:super::color3::Color3=*value.as_userdata().ok_or(mlua::Error::runtime("Expected Color3"))?.borrow()?;
|
|
|
|
|
let typed_value:super::color3::Color3=value.as_userdata().ok_or(mlua::Error::runtime("Expected Color3"))?.take()?;
|
|
|
|
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Color3(typed_value.into()));
|
|
|
|
|
},
|
|
|
|
|
rbx_reflection::DataType::Value(rbx_types::VariantType::Bool)=>{
|
|
|
|
|
@@ -330,14 +331,6 @@ impl mlua::UserData for Instance{
|
|
|
|
|
let typed_value=value.as_str().ok_or(mlua::Error::runtime("Expected boolean"))?;
|
|
|
|
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::String(typed_value.to_owned()));
|
|
|
|
|
},
|
|
|
|
|
rbx_reflection::DataType::Value(rbx_types::VariantType::NumberSequence)=>{
|
|
|
|
|
let typed_value:super::number_sequence::NumberSequence=*value.as_userdata().ok_or(mlua::Error::runtime("Expected NumberSequence"))?.borrow()?;
|
|
|
|
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::NumberSequence(typed_value.into()));
|
|
|
|
|
},
|
|
|
|
|
rbx_reflection::DataType::Value(rbx_types::VariantType::ColorSequence)=>{
|
|
|
|
|
let typed_value:super::color_sequence::ColorSequence=*value.as_userdata().ok_or(mlua::Error::runtime("Expected ColorSequence"))?.borrow()?;
|
|
|
|
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::ColorSequence(typed_value.into()));
|
|
|
|
|
},
|
|
|
|
|
other=>return Err(mlua::Error::runtime(format!("Unimplemented property type: {other:?}"))),
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
@@ -436,18 +429,22 @@ impl ClassMethods<'_>{
|
|
|
|
|
|
|
|
|
|
/// A virtual property pointer definition shorthand.
|
|
|
|
|
type VirtualPropertyFunctionPointer=fn(&rbx_types::Variant)->Option<rbx_types::Variant>;
|
|
|
|
|
type VirtualPropertyFunctionPointerMut=fn(&mut rbx_types::Variant,rbx_types::Variant)->Option<()>;
|
|
|
|
|
const fn vpp(
|
|
|
|
|
property:&'static str,
|
|
|
|
|
pointer:VirtualPropertyFunctionPointer,
|
|
|
|
|
access:VirtualPropertyFunctionPointer,
|
|
|
|
|
access_mut:VirtualPropertyFunctionPointerMut,
|
|
|
|
|
)->VirtualProperty{
|
|
|
|
|
VirtualProperty{
|
|
|
|
|
property,
|
|
|
|
|
pointer,
|
|
|
|
|
access,
|
|
|
|
|
access_mut,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
struct VirtualProperty{
|
|
|
|
|
property:&'static str,// Source property name
|
|
|
|
|
pointer:VirtualPropertyFunctionPointer,
|
|
|
|
|
access:VirtualPropertyFunctionPointer,
|
|
|
|
|
access_mut:VirtualPropertyFunctionPointerMut,
|
|
|
|
|
}
|
|
|
|
|
type VPD=phf::Map<&'static str,// Class name
|
|
|
|
|
phf::Map<&'static str,// Virtual property name
|
|
|
|
|
@@ -456,13 +453,26 @@ type VPD=phf::Map<&'static str,// Class name
|
|
|
|
|
>;
|
|
|
|
|
static VIRTUAL_PROPERTY_DATABASE:VPD=phf::phf_map!{
|
|
|
|
|
"BasePart"=>phf::phf_map!{
|
|
|
|
|
"Position"=>vpp("CFrame",|c:&rbx_types::Variant|{
|
|
|
|
|
let c=match c{
|
|
|
|
|
rbx_types::Variant::CFrame(c)=>c,
|
|
|
|
|
_=>return None,//fail silently and ungracefully
|
|
|
|
|
};
|
|
|
|
|
Some(rbx_types::Variant::Vector3(c.position))
|
|
|
|
|
}),
|
|
|
|
|
"Position"=>vpp(
|
|
|
|
|
"CFrame",
|
|
|
|
|
//Get
|
|
|
|
|
|c|{
|
|
|
|
|
let c=match c{
|
|
|
|
|
rbx_types::Variant::CFrame(c)=>c,
|
|
|
|
|
_=>return None,//fail silently and ungracefully
|
|
|
|
|
};
|
|
|
|
|
Some(rbx_types::Variant::Vector3(c.position))
|
|
|
|
|
},
|
|
|
|
|
//Set
|
|
|
|
|
|c,p|{
|
|
|
|
|
let (c,p)=match (c,p){
|
|
|
|
|
(rbx_types::Variant::CFrame(c),rbx_types::Variant::Vector3(p))=>(c,p),
|
|
|
|
|
_=>return None,//fail silently and ungracefully
|
|
|
|
|
};
|
|
|
|
|
c.position=p;
|
|
|
|
|
Some(())
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@@ -479,5 +489,5 @@ fn find_virtual_property(
|
|
|
|
|
let variant=properties.get(virtual_property.property)?;
|
|
|
|
|
|
|
|
|
|
//Transform Source property with provided function
|
|
|
|
|
(virtual_property.pointer)(variant)
|
|
|
|
|
(virtual_property.access)(variant)
|
|
|
|
|
}
|
|
|
|
|
|