roblox_emulator: use coerce_float32 in CFrame
This commit is contained in:
parent
78593200eb
commit
dabb25b3d3
lib/roblox_emulator/src/runner
@ -1,3 +1,4 @@
|
||||
use super::util::coerce_float32;
|
||||
use super::vector3::Vector3;
|
||||
|
||||
#[derive(Clone,Copy)]
|
||||
@ -93,11 +94,11 @@ pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
|
||||
},
|
||||
//CFrame.new(x,y,z)
|
||||
(
|
||||
mlua::Value::Number(x),mlua::Value::Number(y),Some(z),
|
||||
x,y,Some(z),
|
||||
None,None,None,
|
||||
None,None,None,
|
||||
None,None,None,
|
||||
)=>Ok(CFrame::point(x as f32,y as f32,z)),
|
||||
)=>Ok(CFrame::point(coerce_float32(&x)?,coerce_float32(&y)?,z)),
|
||||
//CFrame.new(x,y,z,xx,yx,zx,xy,yy,zy,xz,yz,zz)
|
||||
(
|
||||
mlua::Value::Number(x),mlua::Value::Number(y),Some(z),
|
||||
|
@ -5,6 +5,7 @@ use rbx_types::Ref;
|
||||
use rbx_dom_weak::{Ustr,InstanceBuilder,WeakDom};
|
||||
|
||||
use crate::runner::vector3::Vector3;
|
||||
use crate::runner::util::coerce_float32;
|
||||
|
||||
// disallow non-static lifetimes
|
||||
fn static_ustr(s:&'static str)->rbx_dom_weak::Ustr{
|
||||
@ -40,13 +41,6 @@ pub fn dom_mut<T>(lua:&mlua::Lua,mut f:impl FnMut(&mut WeakDom)->mlua::Result<T>
|
||||
f(*dom)
|
||||
}
|
||||
|
||||
fn coerce_float32(value:&mlua::Value)->Option<f32>{
|
||||
match value{
|
||||
&mlua::Value::Integer(i)=>Some(i as f32),
|
||||
&mlua::Value::Number(f)=>Some(f as f32),
|
||||
_=>None,
|
||||
}
|
||||
}
|
||||
pub fn class_is_a(class:&str,superclass:&str)->bool{
|
||||
let db=rbx_reflection_database::get();
|
||||
let (Some(class),Some(superclass))=(db.classes.get(class),db.classes.get(superclass))else{
|
||||
@ -304,7 +298,7 @@ impl mlua::UserData for Instance{
|
||||
rbx_types::Variant::Vector3(typed_value.into())
|
||||
},
|
||||
rbx_reflection::DataType::Value(rbx_types::VariantType::Float32)=>{
|
||||
let typed_value:f32=coerce_float32(&value).ok_or_else(||mlua::Error::runtime("Expected f32"))?;
|
||||
let typed_value:f32=coerce_float32(&value)?;
|
||||
rbx_types::Variant::Float32(typed_value)
|
||||
},
|
||||
rbx_reflection::DataType::Enum(enum_name)=>{
|
||||
|
@ -1,6 +1,7 @@
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
mod runner;
|
||||
mod util;
|
||||
|
||||
mod r#enum;
|
||||
mod udim;
|
||||
|
7
lib/roblox_emulator/src/runner/util.rs
Normal file
7
lib/roblox_emulator/src/runner/util.rs
Normal file
@ -0,0 +1,7 @@
|
||||
pub fn coerce_float32(value:&mlua::Value)->mlua::Result<f32>{
|
||||
match value{
|
||||
&mlua::Value::Integer(i)=>Ok(i as f32),
|
||||
&mlua::Value::Number(f)=>Ok(f as f32),
|
||||
_=>Err(mlua::Error::runtime("Expected f32")),
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user