diff --git a/src/luau.rs b/src/luau.rs index 1d85ee4..f357ae3 100644 --- a/src/luau.rs +++ b/src/luau.rs @@ -1,4 +1,4 @@ -use mlua::{Lua as Luau, Result, Table}; +use mlua::{Lua as Luau, Result, Table, Function}; use glam::Vec3; struct StrafeluaGlobals<'a> { @@ -13,19 +13,15 @@ impl<'a> StrafeluaGlobals<'a> { let main_table = &self.current_vm.create_table().unwrap(); main_table.clone() } - fn vector3(&self) -> Table<'a> { - let vec3 = &self.current_vm.create_table().unwrap(); - - - // self.current_vm.create_function(|vm, (x,y,z): (f32,f32,f32)| { - // let vec = Vec3::new(x,y,z); - // vec3.set("x", vec.x).unwrap(); - // vec3.set("y", vec.y).unwrap(); - // vec3.set("z", vec.z).unwrap(); - // Ok(vec3) - // }).unwrap(); - - return vec3.clone() + fn vector3(&self) -> Function { + return self.current_vm.create_function(|vm, (x,y,z): (f32,f32,f32)| { + let glam_vec = Vec3::new(x,y,z); + let vec3 = vm.create_table().unwrap(); + vec3.set("x", glam_vec.x).unwrap(); + vec3.set("y", glam_vec.y).unwrap(); + vec3.set("z", glam_vec.z).unwrap(); + Ok(vec3) + }).unwrap(); } }