diff --git a/src/runner/cframe.rs b/src/runner/cframe.rs index 9bea84f..c1f60fa 100644 --- a/src/runner/cframe.rs +++ b/src/runner/cframe.rs @@ -64,9 +64,53 @@ pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table<'_>)->Result<(),mlua::Err //CFrame.new cframe_table.raw_set("new", - lua.create_function(|_,(x,y,z):(f32,f32,f32)| - Ok(CFrame::point(x,y,z)) - )? + lua.create_function(|_,tuple:( + mlua::Value,mlua::Value,Option, + Option,Option,Option, + Option,Option,Option, + Option,Option,Option, + )|match tuple{ + //CFrame.new(pos) + ( + mlua::Value::UserData(pos),mlua::Value::Nil,None, + None,None,None, + None,None,None, + None,None,None, + )=>{ + let pos:Vector3=pos.take()?; + Ok(CFrame::point(pos.0.x,pos.0.y,pos.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, + )=>{ + let _pos:Vector3=pos.take()?; + let _look:Vector3=look.take()?; + 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