diff --git a/src/runner/cframe.rs b/src/runner/cframe.rs index d3c0890..3c66cef 100644 --- a/src/runner/cframe.rs +++ b/src/runner/cframe.rs @@ -12,6 +12,28 @@ impl CFrame{ } } +pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table<'_>)->Result<(),mlua::Error>{ + let cframe_table=lua.create_table()?; + + //CFrame.new + cframe_table.raw_set("new", + lua.create_function(|ctx,(x,y,z):(f32,f32,f32)| + Ok(ctx.create_userdata(CFrame::new(x,y,z))) + )? + )?; + + //CFrame.Angles + cframe_table.raw_set("Angles", + lua.create_function(|ctx,(x,y,z):(f32,f32,f32)| + Ok(ctx.create_userdata(CFrame::angles(x,y,z))) + )? + )?; + + globals.set("CFrame",cframe_table)?; + + Ok(()) +} + impl mlua::UserData for CFrame{ fn add_fields<'lua,F:mlua::UserDataFields<'lua,Self>>(fields:&mut F){ //CFrame.p diff --git a/src/runner/runner.rs b/src/runner/runner.rs index 74910ed..aaa4547 100644 --- a/src/runner/runner.rs +++ b/src/runner/runner.rs @@ -1,8 +1,5 @@ use crate::context::Context; -use super::vector3::Vector3; -use super::cframe::CFrame; - pub struct Runner{ lua:mlua::Lua, } @@ -31,40 +28,8 @@ fn init(lua:&mlua::Lua)->mlua::Result<()>{ //global environment let globals=lua.globals(); - //Vector3 - { - let vector3_table=lua.create_table()?; - - //Vector3.new - vector3_table.raw_set("new", - lua.create_function(|ctx,(x,y,z):(f32,f32,f32)| - Ok(ctx.create_userdata(Vector3::new(x,y,z))) - )? - )?; - - globals.set("Vector3",vector3_table)?; - } - - //CFrame - { - let cframe_table=lua.create_table()?; - - //CFrame.new - cframe_table.raw_set("new", - lua.create_function(|ctx,(x,y,z):(f32,f32,f32)| - Ok(ctx.create_userdata(CFrame::new(x,y,z))) - )? - )?; - - //CFrame.Angles - cframe_table.raw_set("Angles", - lua.create_function(|ctx,(x,y,z):(f32,f32,f32)| - Ok(ctx.create_userdata(CFrame::angles(x,y,z))) - )? - )?; - - globals.set("CFrame",cframe_table)?; - } + super::vector3::set_globals(lua,&globals)?; + super::cframe::set_globals(lua,&globals)?; Ok(()) } diff --git a/src/runner/vector3.rs b/src/runner/vector3.rs index 2e1942d..78244e5 100644 --- a/src/runner/vector3.rs +++ b/src/runner/vector3.rs @@ -7,6 +7,21 @@ impl Vector3{ } } +pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table<'_>)->Result<(),mlua::Error>{ + let vector3_table=lua.create_table()?; + + //Vector3.new + vector3_table.raw_set("new", + lua.create_function(|ctx,(x,y,z):(f32,f32,f32)| + Ok(ctx.create_userdata(Vector3::new(x,y,z))) + )? + )?; + + globals.set("Vector3",vector3_table)?; + + Ok(()) +} + impl Into for Vector3{ fn into(self)->rbx_types::Vector3{ rbx_types::Vector3::new(self.0.x,self.0.y,self.0.z)