added properties for Vector3 & Vector4:

Vector3.ZERO
Vector3.ONE
Vector3.NEG_ZERO
Vector3.NEG_ONE
Vector3.NEG_X
Vector3.NEG_Y
@Vector4:
Vector4.ZERO
Vector4.ONE
Vector4.NEG_ZERO
Vector4.NEG_ONE
Vector4.NEG_X
Vector4.NEG_Y
This commit is contained in:
unittensor 2024-01-22 12:19:32 -05:00
parent a51001a875
commit 66eea1f106
3 changed files with 121 additions and 20 deletions

View File

@ -22,4 +22,16 @@ print("Vector2.NEG_ZERO=",InspectVectorTable(Vector2.NEG_ZERO))
print("Vector2.NEG_ONE=",InspectVectorTable(Vector2.NEG_ONE)) print("Vector2.NEG_ONE=",InspectVectorTable(Vector2.NEG_ONE))
print("Vector2.NEG_X=",InspectVectorTable(Vector2.NEG_X)) print("Vector2.NEG_X=",InspectVectorTable(Vector2.NEG_X))
print("Vector2.NEG_Y=",InspectVectorTable(Vector2.NEG_Y)) print("Vector2.NEG_Y=",InspectVectorTable(Vector2.NEG_Y))
print("Vector3.ZERO=",InspectVectorTable(Vector3.ZERO))
print("Vector3.ONE=",InspectVectorTable(Vector3.ONE))
print("Vector3.NEG_ZERO=",InspectVectorTable(Vector3.NEG_ZERO))
print("Vector3.NEG_ONE=",InspectVectorTable(Vector3.NEG_ONE))
print("Vector3.NEG_X=",InspectVectorTable(Vector3.NEG_X))
print("Vector3.NEG_Y=",InspectVectorTable(Vector3.NEG_Y))
print("Vector4.ZERO=",InspectVectorTable(Vector4.ZERO))
print("Vector4.ONE=",InspectVectorTable(Vector4.ONE))
print("Vector4.NEG_ZERO=",InspectVectorTable(Vector4.NEG_ZERO))
print("Vector4.NEG_ONE=",InspectVectorTable(Vector4.NEG_ONE))
print("Vector4.NEG_X=",InspectVectorTable(Vector4.NEG_X))
print("Vector4.NEG_Y=",InspectVectorTable(Vector4.NEG_Y))
print("-----------------") print("-----------------")

View File

@ -29,6 +29,7 @@ trait Luavm {
impl Luavm for StrafeluaGlobals { impl Luavm for StrafeluaGlobals {
fn vector2(&self) -> Table { fn vector2(&self) -> Table {
//In a better world, this can all be a macro
let zero = Vec2::ZERO; let zero = Vec2::ZERO;
let one = Vec2::ONE; let one = Vec2::ONE;
let neg_zero = Vec2::ZERO; let neg_zero = Vec2::ZERO;
@ -69,15 +70,14 @@ impl Luavm for StrafeluaGlobals {
field_vector2.set("NEG_X", vector2_neg_x).unwrap(); field_vector2.set("NEG_X", vector2_neg_x).unwrap();
field_vector2.set("NEG_Y", vector2_neg_y).unwrap(); field_vector2.set("NEG_Y", vector2_neg_y).unwrap();
let new_vector2 = self.vm.create_function(|this: &Luau, (x,y): (f32,f32)| { field_vector2.set("new", self.vm.create_function(|this: &Luau, (x,y): (f32,f32)| {
let glam_vec = Vec2::new(x,y); let glam_vec = Vec2::new(x,y);
let vec2 = this.create_table().unwrap(); let vec2 = this.create_table().unwrap();
vec2.set("x", glam_vec.x).unwrap(); vec2.set("x", glam_vec.x).unwrap();
vec2.set("y", glam_vec.y).unwrap(); vec2.set("y", glam_vec.y).unwrap();
Ok(vec2) Ok(vec2)
}).unwrap(); }).unwrap()).unwrap();
field_vector2.set("new", new_vector2).unwrap();
return field_vector2 return field_vector2
} }
@ -85,8 +85,49 @@ impl Luavm for StrafeluaGlobals {
fn vector3(&self) -> Table { fn vector3(&self) -> Table {
let zero = Vec3::ZERO; let zero = Vec3::ZERO;
let one = Vec3::ONE; 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;
let field_vector3 = self.vm.create_table().unwrap(); let field_vector3 = self.vm.create_table().unwrap();
let vector3_one = 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();
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();
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();
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();
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();
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();
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();
let new_vector3 = self.vm.create_function(|this: &Luau, (x,y,z): (f32,f32,f32)| { let new_vector3 = self.vm.create_function(|this: &Luau, (x,y,z): (f32,f32,f32)| {
let glam_vec = Vec3::new(x,y,z); let glam_vec = Vec3::new(x,y,z);
@ -98,19 +139,61 @@ impl Luavm for StrafeluaGlobals {
}).unwrap(); }).unwrap();
field_vector3.set("new", new_vector3).unwrap(); field_vector3.set("new", new_vector3).unwrap();
vector3_one.set("x", one.x).unwrap();
vector3_one.set("y", one.y).unwrap();
vector3_one.set("z", one.z).unwrap();
field_vector3.set("one", vector3_one).unwrap();
return field_vector3; return field_vector3;
} }
fn vector4(&self) -> Table { fn vector4(&self) -> Table {
let zero = Vec4::ZERO; let zero = Vec4::ZERO;
let one = Vec4::ONE; 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;
let field_vector4 = self.vm.create_table().unwrap(); let field_vector4 = self.vm.create_table().unwrap();
let vector4_one = 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();
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();
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();
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();
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();
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();
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();
let new_vector4 = self.vm.create_function(|this: &Luau, (x,y,z,w): (f32,f32,f32,f32)| { let new_vector4 = self.vm.create_function(|this: &Luau, (x,y,z,w): (f32,f32,f32,f32)| {
let glam_vec = Vec4::new(x,y,z,w); let glam_vec = Vec4::new(x,y,z,w);
@ -123,12 +206,6 @@ impl Luavm for StrafeluaGlobals {
}).unwrap(); }).unwrap();
field_vector4.set("new", new_vector4).unwrap(); field_vector4.set("new", new_vector4).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();
field_vector4.set("one", vector4_one).unwrap();
return field_vector4; return field_vector4;
} }

View File

@ -145,6 +145,18 @@ print("Vector2.NEG_ZERO=",InspectVectorTable(Vector2.NEG_ZERO))
print("Vector2.NEG_ONE=",InspectVectorTable(Vector2.NEG_ONE)) print("Vector2.NEG_ONE=",InspectVectorTable(Vector2.NEG_ONE))
print("Vector2.NEG_X=",InspectVectorTable(Vector2.NEG_X)) print("Vector2.NEG_X=",InspectVectorTable(Vector2.NEG_X))
print("Vector2.NEG_Y=",InspectVectorTable(Vector2.NEG_Y)) print("Vector2.NEG_Y=",InspectVectorTable(Vector2.NEG_Y))
print("Vector3.ZERO=",InspectVectorTable(Vector3.ZERO))
print("Vector3.ONE=",InspectVectorTable(Vector3.ONE))
print("Vector3.NEG_ZERO=",InspectVectorTable(Vector3.NEG_ZERO))
print("Vector3.NEG_ONE=",InspectVectorTable(Vector3.NEG_ONE))
print("Vector3.NEG_X=",InspectVectorTable(Vector3.NEG_X))
print("Vector3.NEG_Y=",InspectVectorTable(Vector3.NEG_Y))
print("Vector4.ZERO=",InspectVectorTable(Vector4.ZERO))
print("Vector4.ONE=",InspectVectorTable(Vector4.ONE))
print("Vector4.NEG_ZERO=",InspectVectorTable(Vector4.NEG_ZERO))
print("Vector4.NEG_ONE=",InspectVectorTable(Vector4.NEG_ONE))
print("Vector4.NEG_X=",InspectVectorTable(Vector4.NEG_X))
print("Vector4.NEG_Y=",InspectVectorTable(Vector4.NEG_Y))
print("-----------------") print("-----------------")
"#).exec().expect("Lua syntax error!"); "#).exec().expect("Lua syntax error!");
//Lua syntax error!: SyntaxError { message: "[string \"src/main.rs:122:18\"]:7: Expected ')' (to close '(' at column 7), got ','", incomplete_input: false } //Lua syntax error!: SyntaxError { message: "[string \"src/main.rs:122:18\"]:7: Expected ')' (to close '(' at column 7), got ','", incomplete_input: false }