_VERSION=StrafeLuau 0.9.0, Luau 0.606

This commit is contained in:
unittensor 2024-01-21 20:38:27 -05:00
parent 63c8f0f4f5
commit d2782012ac
2 changed files with 12 additions and 10 deletions

View File

@ -1,5 +1,7 @@
use mlua::{Lua as Luau, Result, Table}; 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 { struct StrafeluaGlobals {
vm: Luau, vm: Luau,
@ -15,6 +17,9 @@ trait Luavm {
vm.globals().set("loadstring", mlua::Nil).unwrap(); 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} StrafeluaGlobals {vm}
} }
fn vector2(&self) -> Table; fn vector2(&self) -> Table;
@ -33,6 +38,7 @@ impl Luavm for StrafeluaGlobals {
vec2.set("y", glam_vec.y).unwrap(); vec2.set("y", glam_vec.y).unwrap();
Ok(vec2) Ok(vec2)
}).unwrap(); }).unwrap();
field_vector2.set("new", new_vector2).unwrap(); field_vector2.set("new", new_vector2).unwrap();
return field_vector2 return field_vector2
@ -49,6 +55,7 @@ impl Luavm for StrafeluaGlobals {
vec3.set("z", glam_vec.z).unwrap(); vec3.set("z", glam_vec.z).unwrap();
Ok(vec3) Ok(vec3)
}).unwrap(); }).unwrap();
field_vector3.set("new", new_vector3).unwrap(); field_vector3.set("new", new_vector3).unwrap();
return field_vector3; return field_vector3;
@ -66,10 +73,13 @@ impl Luavm for StrafeluaGlobals {
vec4.set("w", glam_vec.w).unwrap(); vec4.set("w", glam_vec.w).unwrap();
Ok(vec4) Ok(vec4)
}).unwrap(); }).unwrap();
field_vector4.set("new", new_vector4).unwrap(); field_vector4.set("new", new_vector4).unwrap();
return field_vector4; return field_vector4;
} }
} }
pub fn new_state(isolated: bool) -> Result<Luau> { pub fn new_state(isolated: bool) -> Result<Luau> {

View File

@ -120,15 +120,7 @@ pub fn default_models()->model::IndexedModelInstances{
fn main(){ fn main(){
let strafelua_vm = luau::new_state(true).expect("Failed to load strafe lua"); let strafelua_vm = luau::new_state(true).expect("Failed to load strafe lua");
strafelua_vm.load(r#" strafelua_vm.load(r#"
local v2 = Vector2.new(1, 3) print(_VERSION)
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("-----------------")
"#).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 }
//we got our first lua syntax error, todo: make error an error handler in luau.rs //we got our first lua syntax error, todo: make error an error handler in luau.rs