diff --git a/src/luau.rs b/src/luau.rs index 7eb7c30..e1d73c6 100644 --- a/src/luau.rs +++ b/src/luau.rs @@ -1,5 +1,7 @@ use mlua::{Lua as Luau, Result, Table}; -use glam::{Vec2, Vec3, Vec4}; +use glam::{Vec2, Vec3, Vec4, Quat}; + +const STRAFE_VERSION: &str = env!("CARGO_PKG_VERSION"); struct StrafeluaGlobals { vm: Luau, @@ -15,6 +17,9 @@ trait Luavm { vm.globals().set("loadstring", mlua::Nil).unwrap(); }; + let version_luau: String = vm.globals().get("_VERSION").unwrap(); + vm.globals().set("_VERSION", format!("StrafeLuau {}, {}", STRAFE_VERSION, version_luau)).unwrap(); + StrafeluaGlobals {vm} } fn vector2(&self) -> Table; @@ -33,6 +38,7 @@ impl Luavm for StrafeluaGlobals { vec2.set("y", glam_vec.y).unwrap(); Ok(vec2) }).unwrap(); + field_vector2.set("new", new_vector2).unwrap(); return field_vector2 @@ -49,6 +55,7 @@ impl Luavm for StrafeluaGlobals { vec3.set("z", glam_vec.z).unwrap(); Ok(vec3) }).unwrap(); + field_vector3.set("new", new_vector3).unwrap(); return field_vector3; @@ -66,10 +73,13 @@ impl Luavm for StrafeluaGlobals { vec4.set("w", glam_vec.w).unwrap(); Ok(vec4) }).unwrap(); + field_vector4.set("new", new_vector4).unwrap(); return field_vector4; } + + } pub fn new_state(isolated: bool) -> Result { diff --git a/src/main.rs b/src/main.rs index 5430112..b3a523e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -120,15 +120,7 @@ pub fn default_models()->model::IndexedModelInstances{ fn main(){ let strafelua_vm = luau::new_state(true).expect("Failed to load strafe lua"); strafelua_vm.load(r#" -local v2 = Vector2.new(1, 3) -local v3 = Vector3.new(-10, 30, 50) -local v4 = Vector4.new(50, 30, 10, -1000) - -print("----StrafeLua----") -print(("\n Vector2= x=%d,y=%d \n"):format(v2.x, v2.y)) -print(("\n Vector3= x=%d,y=%d,z=%d \n"):format(v3.x, v3.y, v3.z)) -print(("\n Vector4= x=%d,y=%d,z=%d,w=%d \n"):format(v4.x, v4.y, v4.z, v4.w)) -print("-----------------") + print(_VERSION) "#).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 } //we got our first lua syntax error, todo: make error an error handler in luau.rs