move globals init into their respective files

This commit is contained in:
Quaternions 2024-10-03 16:26:23 -07:00
parent 3bb496f87b
commit a4e2137463
3 changed files with 39 additions and 37 deletions

View File

@ -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{ impl mlua::UserData for CFrame{
fn add_fields<'lua,F:mlua::UserDataFields<'lua,Self>>(fields:&mut F){ fn add_fields<'lua,F:mlua::UserDataFields<'lua,Self>>(fields:&mut F){
//CFrame.p //CFrame.p

View File

@ -1,8 +1,5 @@
use crate::context::Context; use crate::context::Context;
use super::vector3::Vector3;
use super::cframe::CFrame;
pub struct Runner{ pub struct Runner{
lua:mlua::Lua, lua:mlua::Lua,
} }
@ -31,40 +28,8 @@ fn init(lua:&mlua::Lua)->mlua::Result<()>{
//global environment //global environment
let globals=lua.globals(); let globals=lua.globals();
//Vector3 super::vector3::set_globals(lua,&globals)?;
{ super::cframe::set_globals(lua,&globals)?;
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)?;
}
Ok(()) Ok(())
} }

View File

@ -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<rbx_types::Vector3> for Vector3{ impl Into<rbx_types::Vector3> for Vector3{
fn into(self)->rbx_types::Vector3{ fn into(self)->rbx_types::Vector3{
rbx_types::Vector3::new(self.0.x,self.0.y,self.0.z) rbx_types::Vector3::new(self.0.x,self.0.y,self.0.z)