From 38a25147bad4c05bb8716c2bc239840fc78d20da Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 3 Oct 2024 16:26:23 -0700 Subject: [PATCH] move globals init into their respective files --- src/runner/cframe.rs | 22 ++++++++++++++++++++++ src/runner/runner.rs | 36 ++---------------------------------- src/runner/vector3.rs | 15 +++++++++++++++ 3 files changed, 39 insertions(+), 34 deletions(-) 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..f2a7fb5 100644 --- a/src/runner/runner.rs +++ b/src/runner/runner.rs @@ -31,40 +31,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)