Compare commits

..

No commits in common. "e38080f9804d6f09011253f88243cb98ed254e9f" and "2f4e1d64dc10361085da8757f6f98fb8e8cac1ca" have entirely different histories.

5 changed files with 45 additions and 118 deletions

20
Cargo.lock generated
View File

@ -1314,9 +1314,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.78" version = "1.0.76"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -1497,9 +1497,9 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.10.3" version = "1.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@ -1509,9 +1509,9 @@ dependencies = [
[[package]] [[package]]
name = "regex-automata" name = "regex-automata"
version = "0.4.4" version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b7fa1134405e2ec9353fd416b17f8dacd46c473d7d3fd1cf202706a14eb792a" checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@ -2160,9 +2160,9 @@ dependencies = [
[[package]] [[package]]
name = "wgpu" name = "wgpu"
version = "0.19.1" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bfe9a310dcf2e6b85f00c46059aaeaf4184caa8e29a1ecd4b7a704c3482332d" checksum = "d0b71d2ded29e2161db50ab731d6cb42c037bd7ab94864a98fa66ff36b4721a8"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"cfg-if", "cfg-if",
@ -2211,9 +2211,9 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-hal" name = "wgpu-hal"
version = "0.19.1" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3bb47856236bfafc0bc591a925eb036ac19cd987624a447ff353e7a7e7e6f72" checksum = "11f259ceb56727fb097da108d92f8a5cbdb5b74a77f9e396bd43626f67299d61"
dependencies = [ dependencies = [
"android_system_properties", "android_system_properties",
"arrayvec", "arrayvec",

View File

@ -1,9 +1,6 @@
local v2 = Vector2.new(1, 3) type f64 = number
local v3 = Vector3.new(-10, 30, 50) type vec3 = (x: f64, y: f64, z: f64) -> {x: f64, y: f64, z: f64}
local v4 = Vector4.new(50, 30, 10, -1000) local Vector3: vec3 = Vector3
print("----StrafeLua----") local v3 = Vector3(-10, 30, 50)
print(("\n Vector2= x=%d,y=%d \n"):format(v2.x, v2.y)) print((`{("\n"):rep(3)} x=%d,y=%d,z=%d {("\n"):rep(3)}`):format(v3.x, v3.y, v3.z))
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("-----------------")

View File

@ -1,26 +1,17 @@
--A type map for the luau analyzer --A type map for the luau analyzer
type f64 = number type f64 = number
type struct_Vector2 = {x: f64, y: f64} type Vector2 = {x: f64, y: f64}
type struct_Vector3 = struct_Vector2 & {z: f64} type Vector3 = Vector2 & {z: f64}
type struct_Vector4 = struct_Vector3 & {w: f64} type Vector4 = Vector3 & {w: f64}
type Vector2 = { type fn_Vector3 = (x: f64, y: f64, z: f64) -> Vector3
new: (x: f64, y: f64) -> struct_Vector2 local Vector3: fn_Vector3 = Vector3
}
type Vector3 = {
new: (x: f64, y: f64, z: f64) -> struct_Vector3
}
type Vector4 = {
new: (x: f64, y: f64, z: f64, w: f64) -> struct_Vector4
}
local Vector2: Vector2 = Vector2 type fn_Vector3add = (v1: Vector3, v2: Vector3) -> Vector3
local Vector3: Vector3 = Vector3 local Vector3add: fn_Vector3add = Vector3add
local Vector4: Vector4 = Vector4
return { return {
Vector2 = Vector2, Vector3 = Vector3,
Vector3 = Vector3, Vector3add = Vector3add
Vector4 = Vector4,
} }

View File

@ -1,83 +1,35 @@
use mlua::{Lua as Luau, Result, Table}; use mlua::{Lua as Luau, Result, Table, Function};
use glam::{Vec2, Vec3, Vec4}; use glam::Vec3;
struct StrafeluaGlobals { struct StrafeluaGlobals {
vm: Luau, vm: Luau
} }
trait Luavm { impl StrafeluaGlobals {
fn new_vm(isolated: bool) -> StrafeluaGlobals { fn new_vm() -> Self {
let vm = Luau::new(); let vm = Luau::new();
vm.sandbox(isolated).unwrap(); vm.sandbox(true).unwrap();
if isolated { //Prevent bad actors
//Prevent bad actors vm.globals().set("getfenv", mlua::Nil).unwrap(); //Depercated in Luau but not removed *yet*
vm.globals().set("getfenv", mlua::Nil).unwrap(); //Depercated in Luau but not removed *yet* vm.globals().set("setfenv", mlua::Nil).unwrap(); //same with this
vm.globals().set("setfenv", mlua::Nil).unwrap(); //same with this vm.globals().set("loadstring", mlua::Nil).unwrap();
vm.globals().set("loadstring", mlua::Nil).unwrap(); Self {vm}
};
StrafeluaGlobals {vm}
} }
fn vector2(&self) -> Table; fn strafe_player(self) -> Table {
fn vector3(&self) -> Table; self.vm.create_table().unwrap()
fn vector4(&self) -> Table;
}
impl Luavm for StrafeluaGlobals {
fn vector2(&self) -> Table {
let field_vector2 = self.vm.create_table().unwrap();
let new_vector2 = self.vm.create_function(|this: &Luau, (x,y): (f32,f32)| {
let glam_vec = Vec2::new(x,y);
let vec2 = this.create_table().unwrap();
vec2.set("x", glam_vec.x).unwrap();
vec2.set("y", glam_vec.y).unwrap();
Ok(vec2)
}).unwrap();
field_vector2.set("new", new_vector2).unwrap();
return field_vector2
} }
fn vector3(&self) -> Function {
fn vector3(&self) -> Table { return self.vm.create_function(|vm, (x,y,z): (f32,f32,f32)| {
let field_vector3 = self.vm.create_table().unwrap();
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);
let vec3 = this.create_table().unwrap(); let vec3 = vm.create_table().unwrap();
vec3.set("x", glam_vec.x).unwrap(); vec3.set("x", glam_vec.x).unwrap();
vec3.set("y", glam_vec.y).unwrap(); vec3.set("y", glam_vec.y).unwrap();
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();
return field_vector3;
}
fn vector4(&self) -> Table {
let field_vector4 = self.vm.create_table().unwrap();
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 vec4 = this.create_table().unwrap();
vec4.set("x", glam_vec.x).unwrap();
vec4.set("y", glam_vec.y).unwrap();
vec4.set("z", glam_vec.z).unwrap();
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<Luau> { pub fn new_state() -> Result<()> {
let strafelua = StrafeluaGlobals::new_vm(isolated);
Ok(())
strafelua.vm.globals().set("Vector2", strafelua.vector2()).unwrap();
strafelua.vm.globals().set("Vector3", strafelua.vector3()).unwrap();
strafelua.vm.globals().set("Vector4", strafelua.vector4()).unwrap();
Ok(strafelua.vm)
} }

View File

@ -118,20 +118,7 @@ pub fn default_models()->model::IndexedModelInstances{
} }
fn main(){ fn main(){
let strafelua_vm = luau::new_state(true).expect("Failed to load strafe lua"); luau::new_state().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("-----------------")
"#).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
setup::setup_and_start(format!("Strafe Client v{}",env!("CARGO_PKG_VERSION"))); setup::setup_and_start(format!("Strafe Client v{}",env!("CARGO_PKG_VERSION")));
} }