From d9b6085d7fe64a53ffbbac4bce8820e3904fb8c9 Mon Sep 17 00:00:00 2001 From: unittensor Date: Tue, 23 Jan 2024 00:11:15 -0500 Subject: [PATCH] need to patch a bug related to some NEG_X and Y values, start metatable work --- luau/tests/Vector.lua | 53 ++++---- src/luau.rs | 280 +++++++++++++++++++++--------------------- 2 files changed, 172 insertions(+), 161 deletions(-) diff --git a/luau/tests/Vector.lua b/luau/tests/Vector.lua index 53b8878..80581cd 100644 --- a/luau/tests/Vector.lua +++ b/luau/tests/Vector.lua @@ -1,3 +1,5 @@ +--!strict + local v2 = Vector2.new(1, 3) local v3 = Vector3.new(-10, 30, 50) local v4 = Vector4.new(50, 30, 10, -1000) @@ -13,29 +15,32 @@ end print("----StrafeLua----") warn(_VERSION) -print(`Vector2=\t{InspectVectorTable(v2)}`) -print(`Vector3=\t{InspectVectorTable(v3)}`) -print(`Vector4=\t{InspectVectorTable(v4)}`) -print(`Vector2.ZERO=\t{InspectVectorTable(Vector2.ZERO)}`) -print(`Vector2.ONE=\t{InspectVectorTable(Vector2.ONE)}`) -print(`Vector2.NEG_ZERO=\t{InspectVectorTable(Vector2.NEG_ZERO)}`) -print(`Vector2.NEG_ONE=\t{InspectVectorTable(Vector2.NEG_ONE)}`) -print(`Vector2.NEG_X=\t{InspectVectorTable(Vector2.NEG_X)}`) -print(`Vector2.NEG_Y=\t{InspectVectorTable(Vector2.NEG_Y)}`) -print(`Vector3.ZERO=\t{InspectVectorTable(Vector3.ZERO)}`) -print(`Vector3.ONE=\t{InspectVectorTable(Vector3.ONE)}`) -print(`Vector3.NEG_ZERO=\t{InspectVectorTable(Vector3.NEG_ZERO)}`) -print(`Vector3.NEG_ONE=\t{InspectVectorTable(Vector3.NEG_ONE)}`) -print(`Vector3.NEG_X=\t{InspectVectorTable(Vector3.NEG_X)}`) -print(`Vector3.NEG_Y=\t{InspectVectorTable(Vector3.NEG_Y)}`) -print(`Vector4.ZERO=\t{InspectVectorTable(Vector4.ZERO)}`) -print(`Vector4.ONE=\t{InspectVectorTable(Vector4.ONE)}`) -print(`Vector4.NEG_ZERO=\t{InspectVectorTable(Vector4.NEG_ZERO)}`) -print(`Vector4.NEG_ONE=\t{InspectVectorTable(Vector4.NEG_ONE)}`) -print(`Vector4.NEG_X=\t{InspectVectorTable(Vector4.NEG_X)}`) -print(`Vector4.NEG_Y=\t{InspectVectorTable(Vector4.NEG_Y)}`) +print(`Vector2 = \t{InspectVectorTable(v2)}`) +print(`Vector3 = \t{InspectVectorTable(v3)}`) +print(`Vector4 = \t{InspectVectorTable(v4)}`) +print(`Vector2.ZERO = \t{InspectVectorTable(Vector2.ZERO)}`) +print(`Vector2.ONE = \t{InspectVectorTable(Vector2.ONE)}`) +print(`Vector2.NEG_ZERO = \t{InspectVectorTable(Vector2.NEG_ZERO)}`) +print(`Vector2.NEG_ONE = \t{InspectVectorTable(Vector2.NEG_ONE)}`) +print(`Vector2.NEG_X = \t{InspectVectorTable(Vector2.NEG_X)}`) +print(`Vector2.NEG_Y = \t{InspectVectorTable(Vector2.NEG_Y)}`) +print(`Vector3.ZERO = \t{InspectVectorTable(Vector3.ZERO)}`) +print(`Vector3.ONE = \t{InspectVectorTable(Vector3.ONE)}`) +print(`Vector3.NEG_ZERO = \t{InspectVectorTable(Vector3.NEG_ZERO)}`) +print(`Vector3.NEG_ONE = \t{InspectVectorTable(Vector3.NEG_ONE)}`) +print(`Vector3.NEG_X = \t{InspectVectorTable(Vector3.NEG_X)}`) +print(`Vector3.NEG_Y = \t{InspectVectorTable(Vector3.NEG_Y)}`) +print(`Vector3.NEG_Z = \t{InspectVectorTable(Vector3.NEG_Z)}`) +print(`Vector4.ZERO = \t{InspectVectorTable(Vector4.ZERO)}`) +print(`Vector4.ONE = \t{InspectVectorTable(Vector4.ONE)}`) +print(`Vector4.NEG_ZERO = \t{InspectVectorTable(Vector4.NEG_ZERO)}`) +print(`Vector4.NEG_ONE = \t{InspectVectorTable(Vector4.NEG_ONE)}`) +print(`Vector4.NEG_X = \t{InspectVectorTable(Vector4.NEG_X)}`) +print(`Vector4.NEG_Y = \t{InspectVectorTable(Vector4.NEG_Y)}`) +print(`Vector4.NEG_Z = \t{InspectVectorTable(Vector4.NEG_Z)}`) +print(`Vector4.NEG_W = \t{InspectVectorTable(Vector4.NEG_W)}`) print("-----------------") -print(`No args Vector2.new=\t{InspectVectorTable(Vector2.new())}`) -print(`No args Vector3.new=\t{InspectVectorTable(Vector3.new())}`) -print(`No args Vector4.new=\t{InspectVectorTable(Vector4.new())}`) +print(`No args Vector2.new = \t{InspectVectorTable(Vector2.new())}`) +print(`No args Vector3.new = \t{InspectVectorTable(Vector3.new())}`) +print(`No args Vector4.new = \t{InspectVectorTable(Vector4.new())}`) print("-----------------") \ No newline at end of file diff --git a/src/luau.rs b/src/luau.rs index a941c2d..e7b8ca3 100644 --- a/src/luau.rs +++ b/src/luau.rs @@ -1,4 +1,4 @@ -use mlua::{Lua as Luau, Result, Table, Function}; +use mlua::{Lua as Luau, Result}; use glam::{Vec2, Vec3, Vec4, Quat}; use color_print::cprintln; @@ -8,6 +8,28 @@ struct StrafeluaGlobals { vm: Luau, } trait Luavm { + const VEC2_ZERO: Vec2 = Vec2::ZERO; + const VEC2_ONE: Vec2 = Vec2::ONE; + const VEC2_NEG_ZERO: Vec2 = Vec2::ZERO; + const VEC2_NEG_ONE: Vec2 = Vec2::NEG_ONE; + const VEC2_NEG_X: Vec2 = Vec2::NEG_X; + const VEC2_NEG_Y: Vec2 = Vec2::NEG_Y; + const VEC3_ZERO: Vec3 = Vec3::ZERO; + const VEC3_ONE: Vec3 = Vec3::ONE; + const VEC3_NEG_ZERO: Vec3 = Vec3::ZERO; + const VEC3_NEG_ONE: Vec3 = Vec3::NEG_ONE; + const VEC3_NEG_X: Vec3 = Vec3::NEG_X; + const VEC3_NEG_Y: Vec3 = Vec3::NEG_Y; + const VEC3_NEG_Z: Vec3 = Vec3::NEG_Z; + const VEC4_ZERO: Vec4 = Vec4::ZERO; + const VEC4_ONE: Vec4 = Vec4::ONE; + const VEC4_NEG_ZERO: Vec4 = Vec4::ZERO; + const VEC4_NEG_ONE: Vec4 = Vec4::NEG_ONE; + const VEC4_NEG_X: Vec4 = Vec4::NEG_X; + const VEC4_NEG_Y: Vec4 = Vec4::NEG_Y; + const VEC4_NEG_Z: Vec4 = Vec4::NEG_Z; + const VEC4_NEG_W: Vec4 = Vec4::NEG_W; + fn new_vm(isolated: bool) -> StrafeluaGlobals { let vm = Luau::new(); vm.sandbox(isolated).unwrap(); @@ -23,74 +45,73 @@ trait Luavm { StrafeluaGlobals {vm} } - fn warn(&self) -> Function; - fn vector2(&self) -> Table; - fn vector3(&self) -> Table; - fn vector4(&self) -> Table; + fn warn(&self) -> mlua::Function; + fn vector2(&self) -> mlua::Table; + fn vector3(&self) -> mlua::Table; + fn vector4(&self) -> mlua::Table; +} + +trait Vectors { + fn arg(result: Option) -> f32; +} +impl Vectors for StrafeluaGlobals { + fn arg(result: Option) -> f32 { + match result { + Some(n) => n as f32, + None => 0.0 as f32, + } + } } impl Luavm for StrafeluaGlobals { //Debug stuff - fn warn(&self) -> Function { + fn warn(&self) -> mlua::Function { return self.vm.create_function(|_, message: mlua::String| { match Some(message) { - Some(lua_string) => cprintln!("{}", lua_string.to_str().unwrap()), - None => println!("Nothing provided to warn"), + Some(lua_string) => cprintln!("{}", lua_string.to_str().unwrap()), + None => println!("Nothing provided to warn"), }; Ok(()) }).unwrap(); } - fn vector2(&self) -> Table { - let zero = Vec2::ZERO; - let one = Vec2::ONE; - let neg_zero = Vec2::ZERO; - let neg_one = Vec2::NEG_ONE; - let neg_x = Vec2::NEG_X; - let neg_y = Vec2::NEG_Y; - + fn vector2(&self) -> mlua::Table { let field_vector2 = self.vm.create_table().unwrap(); let vector2_one = self.vm.create_table().unwrap(); - vector2_one.set("x", one.x).unwrap(); - vector2_one.set("y", one.y).unwrap(); + vector2_one.set("x", Self::VEC2_ONE.x).unwrap(); + vector2_one.set("y", Self::VEC2_ONE.y).unwrap(); let vector2_zero = self.vm.create_table().unwrap(); - vector2_zero.set("x", zero.x).unwrap(); - vector2_zero.set("y", zero.y).unwrap(); + vector2_zero.set("x", Self::VEC2_ZERO.x).unwrap(); + vector2_zero.set("y", Self::VEC2_ZERO.y).unwrap(); let vector2_neg_zero = self.vm.create_table().unwrap(); - vector2_neg_zero.set("x", neg_zero.x).unwrap(); - vector2_neg_zero.set("y", neg_zero.y).unwrap(); + vector2_neg_zero.set("x", Self::VEC2_NEG_ZERO.x).unwrap(); + vector2_neg_zero.set("y", Self::VEC2_NEG_ZERO.y).unwrap(); let vector2_neg_one = self.vm.create_table().unwrap(); - vector2_neg_one.set("x", neg_one.x).unwrap(); - vector2_neg_one.set("y", neg_one.y).unwrap(); + vector2_neg_one.set("x", Self::VEC2_NEG_ONE.x).unwrap(); + vector2_neg_one.set("y", Self::VEC2_NEG_ONE.y).unwrap(); let vector2_neg_x = self.vm.create_table().unwrap(); - vector2_neg_x.set("x", neg_x.x).unwrap(); - vector2_neg_x.set("y", neg_x.y).unwrap(); + vector2_neg_x.set("x", Self::VEC2_NEG_X.x).unwrap(); + vector2_neg_x.set("y", Self::VEC2_NEG_X.y).unwrap(); let vector2_neg_y = self.vm.create_table().unwrap(); - vector2_neg_y.set("x", neg_y.x).unwrap(); - vector2_neg_y.set("y", neg_y.y).unwrap(); + vector2_neg_y.set("x", Self::VEC2_NEG_Y.x).unwrap(); + vector2_neg_y.set("y", Self::VEC2_NEG_Y.y).unwrap(); - field_vector2.set("ONE", vector2_one).unwrap(); - field_vector2.set("ZERO", vector2_zero).unwrap(); + field_vector2.set("ONE", vector2_one).unwrap(); + field_vector2.set("ZERO", vector2_zero).unwrap(); field_vector2.set("NEG_ZERO", vector2_neg_zero).unwrap(); - field_vector2.set("NEG_ONE", vector2_neg_one).unwrap(); - field_vector2.set("NEG_X", vector2_neg_x).unwrap(); - field_vector2.set("NEG_Y", vector2_neg_y).unwrap(); + field_vector2.set("NEG_ONE", vector2_neg_one).unwrap(); + field_vector2.set("NEG_X", vector2_neg_x).unwrap(); + field_vector2.set("NEG_Y", vector2_neg_y).unwrap(); field_vector2.set("new", self.vm.create_function(|this: &Luau, (x,y): (Option, Option)| { - let vec2_x = match x { - Some(n) => n as f32, - None => 0.0 as f32, - }; - let vec2_y = match y { - Some(n) => n as f32, - None => 0.0 as f32, - }; + let vec2_x = ::arg(x); + let vec2_y = Vectors::arg(y); let glam_vec = Vec2::new(vec2_x,vec2_y); let vec2 = this.create_table().unwrap(); vec2.set("x", glam_vec.x).unwrap(); @@ -102,66 +123,56 @@ impl Luavm for StrafeluaGlobals { return field_vector2 } - fn vector3(&self) -> Table { - let zero = Vec3::ZERO; - let one = Vec3::ONE; - let neg_zero = Vec3::ZERO; - let neg_one = Vec3::NEG_ONE; - let neg_x = Vec3::NEG_X; - let neg_y = Vec3::NEG_Y; - + fn vector3(&self) -> mlua::Table { let field_vector3 = self.vm.create_table().unwrap(); let vector3_one = self.vm.create_table().unwrap(); - vector3_one.set("x", one.x).unwrap(); - vector3_one.set("y", one.y).unwrap(); - vector3_one.set("z", one.z).unwrap(); + vector3_one.set("x", Self::VEC3_ONE.x).unwrap(); + vector3_one.set("y", Self::VEC3_ONE.y).unwrap(); + vector3_one.set("z", Self::VEC3_ONE.z).unwrap(); let vector3_zero = self.vm.create_table().unwrap(); - vector3_zero.set("x", zero.x).unwrap(); - vector3_zero.set("y", zero.y).unwrap(); - vector3_zero.set("z", zero.z).unwrap(); + vector3_zero.set("x", Self::VEC3_ZERO.x).unwrap(); + vector3_zero.set("y", Self::VEC3_ZERO.y).unwrap(); + vector3_zero.set("z", Self::VEC3_ZERO.z).unwrap(); let vector3_neg_zero = self.vm.create_table().unwrap(); - vector3_neg_zero.set("x", neg_zero.x).unwrap(); - vector3_neg_zero.set("y", neg_zero.y).unwrap(); - vector3_neg_zero.set("z", neg_zero.z).unwrap(); + vector3_neg_zero.set("x", Self::VEC3_NEG_ZERO.x).unwrap(); + vector3_neg_zero.set("y", Self::VEC3_NEG_ZERO.y).unwrap(); + vector3_neg_zero.set("z", Self::VEC3_NEG_ZERO.z).unwrap(); let vector3_neg_one = self.vm.create_table().unwrap(); - vector3_neg_one.set("x", neg_one.x).unwrap(); - vector3_neg_one.set("y", neg_one.y).unwrap(); - vector3_neg_one.set("z", neg_one.z).unwrap(); + vector3_neg_one.set("x", Self::VEC3_NEG_ONE.x).unwrap(); + vector3_neg_one.set("y", Self::VEC3_NEG_ONE.y).unwrap(); + vector3_neg_one.set("z", Self::VEC3_NEG_ONE.z).unwrap(); let vector3_neg_x = self.vm.create_table().unwrap(); - vector3_neg_x.set("x", neg_x.x).unwrap(); - vector3_neg_x.set("y", neg_x.y).unwrap(); - vector3_neg_x.set("z", neg_x.z).unwrap(); + vector3_neg_x.set("x", Self::VEC3_NEG_X.x).unwrap(); + vector3_neg_x.set("y", Self::VEC3_NEG_X.y).unwrap(); + vector3_neg_x.set("z", Self::VEC3_NEG_X.z).unwrap(); let vector3_neg_y = self.vm.create_table().unwrap(); - vector3_neg_y.set("x", neg_y.x).unwrap(); - vector3_neg_y.set("y", neg_y.y).unwrap(); - vector3_neg_y.set("y", neg_y.z).unwrap(); + vector3_neg_y.set("x", Self::VEC3_NEG_Y.x).unwrap(); + vector3_neg_y.set("y", Self::VEC3_NEG_Y.y).unwrap(); + vector3_neg_x.set("z", Self::VEC3_NEG_Y.z).unwrap(); - field_vector3.set("ONE", vector3_one).unwrap(); - field_vector3.set("ZERO", vector3_zero).unwrap(); + let vector3_neg_z = self.vm.create_table().unwrap(); + vector3_neg_z.set("x", Self::VEC3_NEG_Z.x).unwrap(); + vector3_neg_z.set("y", Self::VEC3_NEG_Z.y).unwrap(); + vector3_neg_z.set("z", Self::VEC3_NEG_Z.z).unwrap(); + + field_vector3.set("ONE", vector3_one).unwrap(); + field_vector3.set("ZERO", vector3_zero).unwrap(); field_vector3.set("NEG_ZERO", vector3_neg_zero).unwrap(); - field_vector3.set("NEG_ONE", vector3_neg_one).unwrap(); - field_vector3.set("NEG_X", vector3_neg_x).unwrap(); - field_vector3.set("NEG_Y", vector3_neg_y).unwrap(); + field_vector3.set("NEG_ONE", vector3_neg_one).unwrap(); + field_vector3.set("NEG_X", vector3_neg_x).unwrap(); + field_vector3.set("NEG_Y", vector3_neg_y).unwrap(); + field_vector3.set("NEG_Z", vector3_neg_z).unwrap(); field_vector3.set("new", self.vm.create_function(|this: &Luau, (x,y,z): (Option, Option, Option)| { - let vec3_x = match x { - Some(n) => n as f32, - None => 0.0 as f32, - }; - let vec3_y = match y { - Some(n) => n as f32, - None => 0.0 as f32, - }; - let vec3_z = match z { - Some(n) => n as f32, - None => 0.0 as f32, - }; + let vec3_x = vector_arg(x); + let vec3_y = vector_arg(y); + let vec3_z = vector_arg(z); let glam_vec = Vec3::new(vec3_x,vec3_y,vec3_z); let vec3 = this.create_table().unwrap(); vec3.set("x", glam_vec.x).unwrap(); @@ -173,76 +184,71 @@ impl Luavm for StrafeluaGlobals { return field_vector3; } - fn vector4(&self) -> Table { - let zero = Vec4::ZERO; - let one = Vec4::ONE; - let neg_zero = Vec4::ZERO; - let neg_one = Vec4::NEG_ONE; - let neg_x = Vec4::NEG_X; - let neg_y = Vec4::NEG_Y; - + fn vector4(&self) -> mlua::Table { let field_vector4 = self.vm.create_table().unwrap(); let vector4_one = self.vm.create_table().unwrap(); - vector4_one.set("x", one.x).unwrap(); - vector4_one.set("y", one.y).unwrap(); - vector4_one.set("z", one.z).unwrap(); - vector4_one.set("w", one.w).unwrap(); + vector4_one.set("x", Self::VEC4_ONE.x).unwrap(); + vector4_one.set("y", Self::VEC4_ONE.y).unwrap(); + vector4_one.set("z", Self::VEC4_ONE.z).unwrap(); + vector4_one.set("w", Self::VEC4_ONE.w).unwrap(); let vector4_zero = self.vm.create_table().unwrap(); - vector4_zero.set("x", zero.x).unwrap(); - vector4_zero.set("y", zero.y).unwrap(); - vector4_zero.set("z", zero.z).unwrap(); - vector4_zero.set("w", zero.w).unwrap(); + vector4_zero.set("x", Self::VEC4_ZERO.x).unwrap(); + vector4_zero.set("y", Self::VEC4_ZERO.y).unwrap(); + vector4_zero.set("z", Self::VEC4_ZERO.z).unwrap(); + vector4_zero.set("w", Self::VEC4_ZERO.w).unwrap(); let vector4_neg_zero = self.vm.create_table().unwrap(); - vector4_neg_zero.set("x", neg_zero.x).unwrap(); - vector4_neg_zero.set("y", neg_zero.y).unwrap(); - vector4_neg_zero.set("z", neg_zero.z).unwrap(); - vector4_neg_zero.set("w", neg_zero.w).unwrap(); + vector4_neg_zero.set("x", Self::VEC4_NEG_ZERO.x).unwrap(); + vector4_neg_zero.set("y", Self::VEC4_NEG_ZERO.y).unwrap(); + vector4_neg_zero.set("z", Self::VEC4_NEG_ZERO.z).unwrap(); + vector4_neg_zero.set("w", Self::VEC4_NEG_ZERO.w).unwrap(); let vector4_neg_one = self.vm.create_table().unwrap(); - vector4_neg_one.set("x", neg_one.x).unwrap(); - vector4_neg_one.set("y", neg_one.y).unwrap(); - vector4_neg_one.set("z", neg_one.z).unwrap(); - vector4_neg_one.set("w", neg_one.w).unwrap(); + vector4_neg_one.set("x", Self::VEC4_NEG_ONE.x).unwrap(); + vector4_neg_one.set("y", Self::VEC4_NEG_ONE.y).unwrap(); + vector4_neg_one.set("z", Self::VEC4_NEG_ONE.z).unwrap(); + vector4_neg_one.set("w", Self::VEC4_NEG_ONE.w).unwrap(); let vector4_neg_x = self.vm.create_table().unwrap(); - vector4_neg_x.set("x", neg_x.x).unwrap(); - vector4_neg_x.set("y", neg_x.y).unwrap(); - vector4_neg_x.set("z", neg_x.z).unwrap(); - vector4_neg_x.set("w", neg_x.w).unwrap(); + vector4_neg_x.set("x", Self::VEC4_NEG_X.x).unwrap(); + vector4_neg_x.set("y", Self::VEC4_NEG_X.y).unwrap(); + vector4_neg_x.set("z", Self::VEC4_NEG_X.z).unwrap(); + vector4_neg_x.set("w", Self::VEC4_NEG_X.w).unwrap(); let vector4_neg_y = self.vm.create_table().unwrap(); - vector4_neg_y.set("x", neg_y.x).unwrap(); - vector4_neg_y.set("y", neg_y.y).unwrap(); - vector4_neg_y.set("y", neg_y.z).unwrap(); - vector4_neg_y.set("w", neg_y.w).unwrap(); + vector4_neg_y.set("x", Self::VEC4_NEG_Y.x).unwrap(); + vector4_neg_y.set("y", Self::VEC4_NEG_Y.y).unwrap(); + vector4_neg_x.set("z", Self::VEC4_NEG_Y.z).unwrap(); + vector4_neg_x.set("w", Self::VEC4_NEG_Y.w).unwrap(); - field_vector4.set("ONE", vector4_one).unwrap(); - field_vector4.set("ZERO", vector4_zero).unwrap(); + let vector4_neg_z = self.vm.create_table().unwrap(); + vector4_neg_z.set("x", Self::VEC4_NEG_Z.x).unwrap(); + vector4_neg_z.set("y", Self::VEC4_NEG_Z.y).unwrap(); + vector4_neg_z.set("z", Self::VEC4_NEG_Z.z).unwrap(); + vector4_neg_z.set("w", Self::VEC4_NEG_Z.w).unwrap(); + + let vector4_neg_w = self.vm.create_table().unwrap(); + vector4_neg_w.set("x", Self::VEC4_NEG_W.x).unwrap(); + vector4_neg_w.set("y", Self::VEC4_NEG_W.y).unwrap(); + vector4_neg_w.set("z", Self::VEC4_NEG_W.z).unwrap(); + vector4_neg_w.set("w", Self::VEC4_NEG_W.w).unwrap(); + + field_vector4.set("ONE", vector4_one).unwrap(); + field_vector4.set("ZERO", vector4_zero).unwrap(); field_vector4.set("NEG_ZERO", vector4_neg_zero).unwrap(); - field_vector4.set("NEG_ONE", vector4_neg_one).unwrap(); - field_vector4.set("NEG_X", vector4_neg_x).unwrap(); - field_vector4.set("NEG_Y", vector4_neg_y).unwrap(); + field_vector4.set("NEG_ONE", vector4_neg_one).unwrap(); + field_vector4.set("NEG_X", vector4_neg_x).unwrap(); + field_vector4.set("NEG_Y", vector4_neg_y).unwrap(); + field_vector4.set("NEG_Z", vector4_neg_z).unwrap(); + field_vector4.set("NEG_W", vector4_neg_w).unwrap(); let new_vector4 = self.vm.create_function(|this: &Luau, (x,y,z,w): (Option, Option, Option, Option)| { - let vec4_x = match x { - Some(n) => n as f32, - None => 0.0 as f32, - }; - let vec4_y = match y { - Some(n) => n as f32, - None => 0.0 as f32, - }; - let vec4_z = match z { - Some(n) => n as f32, - None => 0.0 as f32, - }; - let vec4_w = match w { - Some(n) => n as f32, - None => 0.0 as f32, - }; + let vec4_x = vector_arg(x); + let vec4_y = vector_arg(y); + let vec4_z = vector_arg(z); + let vec4_w = vector_arg(w); let glam_vec = Vec4::new(vec4_x,vec4_y,vec4_z,vec4_w); let vec4 = this.create_table().unwrap(); vec4.set("x", glam_vec.x).unwrap();