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

View File

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

View File

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

View File

@ -1,83 +1,35 @@
use mlua::{Lua as Luau, Result, Table};
use glam::{Vec2, Vec3, Vec4};
use mlua::{Lua as Luau, Result, Table, Function};
use glam::Vec3;
struct StrafeluaGlobals {
vm: Luau,
vm: Luau
}
trait Luavm {
fn new_vm(isolated: bool) -> StrafeluaGlobals {
impl StrafeluaGlobals {
fn new_vm() -> Self {
let vm = Luau::new();
vm.sandbox(isolated).unwrap();
if isolated {
//Prevent bad actors
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("loadstring", mlua::Nil).unwrap();
};
StrafeluaGlobals {vm}
vm.sandbox(true).unwrap();
//Prevent bad actors
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("loadstring", mlua::Nil).unwrap();
Self {vm}
}
fn vector2(&self) -> Table;
fn vector3(&self) -> Table;
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 strafe_player(self) -> Table {
self.vm.create_table().unwrap()
}
fn vector3(&self) -> Table {
let field_vector3 = self.vm.create_table().unwrap();
let new_vector3 = self.vm.create_function(|this: &Luau, (x,y,z): (f32,f32,f32)| {
fn vector3(&self) -> Function {
return self.vm.create_function(|vm, (x,y,z): (f32,f32,f32)| {
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("y", glam_vec.y).unwrap();
vec3.set("z", glam_vec.z).unwrap();
Ok(vec3)
}).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> {
let strafelua = StrafeluaGlobals::new_vm(isolated);
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)
pub fn new_state() -> Result<()> {
Ok(())
}

View File

@ -118,20 +118,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("-----------------")
"#).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
luau::new_state().expect("Failed to load strafe lua");
setup::setup_and_start(format!("Strafe Client v{}",env!("CARGO_PKG_VERSION")));
}