CFrame.new

This commit is contained in:
Quaternions 2024-10-05 12:34:30 -07:00
parent ff9c122470
commit e02e455990

View File

@ -64,9 +64,49 @@ pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table<'_>)->Result<(),mlua::Err
//CFrame.new //CFrame.new
cframe_table.raw_set("new", cframe_table.raw_set("new",
lua.create_function(|_,(x,y,z):(f32,f32,f32)| lua.create_function(|_,tuple:(
Ok(CFrame::point(x,y,z)) mlua::Value,mlua::Value,Option<f32>,
)? Option<f32>,Option<f32>,Option<f32>,
Option<f32>,Option<f32>,Option<f32>,
Option<f32>,Option<f32>,Option<f32>,
)|match tuple{
//CFrame.new(pos)
(
mlua::Value::UserData(ud),mlua::Value::Nil,None,
None,None,None,
None,None,None,
None,None,None,
)=>{
let v:Vector3=ud.take()?;
Ok(CFrame::point(v.0.x,v.0.y,v.0.z))
},
//TODO: CFrame.new(pos,look)
(
mlua::Value::UserData(_pos),mlua::Value::UserData(_look),None,
None,None,None,
None,None,None,
None,None,None,
)=>Err(mlua::Error::runtime("Not yet implemented")),
//CFrame.new(x,y,z)
(
mlua::Value::Number(x),mlua::Value::Number(y),Some(z),
None,None,None,
None,None,None,
None,None,None,
)=>Ok(CFrame::point(x as f32,y as f32,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),
Some(xx),Some(yx),Some(zx),
Some(xy),Some(yy),Some(zy),
Some(xz),Some(yz),Some(zz),
)=>Ok(CFrame::new(x as f32,y as f32,z,
xx,yx,zx,
xy,yy,zy,
xz,yz,zz,
)),
_=>Err(mlua::Error::runtime("Invalid arguments"))
})?
)?; )?;
//CFrame.Angles //CFrame.Angles