coerce_float32

This commit is contained in:
Quaternions 2024-09-20 17:54:16 -07:00
parent 930ac1c331
commit 701897b00d

View File

@ -30,7 +30,7 @@ fn dom<T>(lua:&mlua::Lua,mut f:impl FnMut(&mut WeakDom)->mlua::Result<T>)->mlua:
f(&mut *dom) f(&mut *dom)
} }
fn coerce_float(value:&mlua::Value)->Option<f32>{ fn coerce_float32(value:&mlua::Value)->Option<f32>{
match value{ match value{
&mlua::Value::Integer(i)=>Some(i as f32), &mlua::Value::Integer(i)=>Some(i as f32),
&mlua::Value::Number(f)=>Some(f as f32), &mlua::Value::Number(f)=>Some(f as f32),
@ -96,7 +96,7 @@ impl mlua::UserData for Instance{
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Vector3(typed_value.into())); instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Vector3(typed_value.into()));
}, },
rbx_types::Variant::Float32(_)=>{ rbx_types::Variant::Float32(_)=>{
let typed_value:f32=coerce_float(&value).ok_or(mlua::Error::runtime("Expected f32"))?; let typed_value:f32=coerce_float32(&value).ok_or(mlua::Error::runtime("Expected f32"))?;
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Float32(typed_value)); instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Float32(typed_value));
}, },
other=>println!("Unimplemented property type: {other:?}"), other=>println!("Unimplemented property type: {other:?}"),