Compare commits

..

No commits in common. "d9b6085d7fe64a53ffbbac4bce8820e3904fb8c9" and "e40e960ef2cc0ca8f0dcb582467c1661f593677f" have entirely different histories.

4 changed files with 168 additions and 231 deletions

View File

@ -1,52 +0,0 @@
type workspace = {[string]: {number}}
type Service = {}
export type exports = {[string]: {workspace | number | {}}}
local workspace: workspace = {}
local RS = {
RenderStepped = {},
Stepped = {},
Heartbeat = {}
}
local game = setmetatable({
Workspace = workspace,
Players = {},
RunService = RS
}, {
__index = function(self,i)
return rawget(self,i)
end,
__newindex = function(self,i,_)
--Roblox actually does this
local t = type(i)
return t == "Object" and "Unable to assign property Game. Property is read only" or `Unable to assign property Game. Object expected, got {t}`
end,
__metatable = "This metatable is locked."
})
function game:GetService(service: string): Service
return self[service]
end
function game:service(service: string): Service
return self:GetService(service)
end
function game:FindService(service: string): boolean | Service
return self[service] and self[service]
end
local tick = os.clock() --just be better (Roblox wants you to use this instead of "tick" anyways because of Wine)
local task = {
wait = {},
delay = {},
defer = {}
}
local exports: exports = {
game = game, Game = game,
workspace = workspace, Workspace = workspace,
tick = tick,
task = task
}
return exports

View File

@ -1,5 +1,3 @@
--!strict
local v2 = Vector2.new(1, 3)
local v3 = Vector3.new(-10, 30, 50)
local v4 = Vector4.new(50, 30, 10, -1000)
@ -30,15 +28,12 @@ print(`Vector3.NEG_ZERO = \t{InspectVectorTable(Vector3.NEG_ZERO)}`)
print(`Vector3.NEG_ONE=\t{InspectVectorTable(Vector3.NEG_ONE)}`)
print(`Vector3.NEG_X=\t{InspectVectorTable(Vector3.NEG_X)}`)
print(`Vector3.NEG_Y=\t{InspectVectorTable(Vector3.NEG_Y)}`)
print(`Vector3.NEG_Z = \t{InspectVectorTable(Vector3.NEG_Z)}`)
print(`Vector4.ZERO=\t{InspectVectorTable(Vector4.ZERO)}`)
print(`Vector4.ONE=\t{InspectVectorTable(Vector4.ONE)}`)
print(`Vector4.NEG_ZERO=\t{InspectVectorTable(Vector4.NEG_ZERO)}`)
print(`Vector4.NEG_ONE=\t{InspectVectorTable(Vector4.NEG_ONE)}`)
print(`Vector4.NEG_X=\t{InspectVectorTable(Vector4.NEG_X)}`)
print(`Vector4.NEG_Y=\t{InspectVectorTable(Vector4.NEG_Y)}`)
print(`Vector4.NEG_Z = \t{InspectVectorTable(Vector4.NEG_Z)}`)
print(`Vector4.NEG_W = \t{InspectVectorTable(Vector4.NEG_W)}`)
print("-----------------")
print(`No args Vector2.new=\t{InspectVectorTable(Vector2.new())}`)
print(`No args Vector3.new=\t{InspectVectorTable(Vector3.new())}`)

View File

@ -1,14 +1,14 @@
--A type map for the luau analyzer
type f32 = number
type f64 = number
type struct_Vector2 = {x: f32, y: f32}
type struct_Vector3 = struct_Vector2 & {z: f32}
type struct_Vector4 = struct_Vector3 & {w: f32}
type struct_Vector2 = {x: f64, y: f64}
type struct_Vector3 = struct_Vector2 & {z: f64}
type struct_Vector4 = struct_Vector3 & {w: f64}
export type warn = (message: string) -> ()
export type Vector2 = {
new: (x: f32?, y: f32?) -> struct_Vector2,
new: (x: f64?, y: f64?) -> struct_Vector2,
ONE: struct_Vector2,
ZERO: struct_Vector2,
NEG_ZERO: struct_Vector2,
@ -17,7 +17,7 @@ export type Vector2 = {
NEG_Y: struct_Vector2,
}
export type Vector3 = {
new: (x: f32?, y: f32?, z: f32?) -> struct_Vector3,
new: (x: f64?, y: f64?, z: f64?) -> struct_Vector3,
ONE: struct_Vector3,
ZERO: struct_Vector3,
NEG_ZERO: struct_Vector3,
@ -26,7 +26,7 @@ export type Vector3 = {
NEG_Y: struct_Vector3,
}
export type Vector4 = {
new: (x: f32?, y: f32?, z: f32?, w: f32?) -> struct_Vector4,
new: (x: f64?, y: f64?, z: f64?, w: f64?) -> struct_Vector4,
ONE: struct_Vector4,
ZERO: struct_Vector4,
NEG_ZERO: struct_Vector4,

View File

@ -1,4 +1,4 @@
use mlua::{Lua as Luau, Result};
use mlua::{Lua as Luau, Result, Table, Function};
use glam::{Vec2, Vec3, Vec4, Quat};
use color_print::cprintln;
@ -8,28 +8,6 @@ struct StrafeluaGlobals {
vm: Luau,
}
trait Luavm {
const VEC2_ZERO: Vec2 = Vec2::ZERO;
const VEC2_ONE: Vec2 = Vec2::ONE;
const VEC2_NEG_ZERO: Vec2 = Vec2::ZERO;
const VEC2_NEG_ONE: Vec2 = Vec2::NEG_ONE;
const VEC2_NEG_X: Vec2 = Vec2::NEG_X;
const VEC2_NEG_Y: Vec2 = Vec2::NEG_Y;
const VEC3_ZERO: Vec3 = Vec3::ZERO;
const VEC3_ONE: Vec3 = Vec3::ONE;
const VEC3_NEG_ZERO: Vec3 = Vec3::ZERO;
const VEC3_NEG_ONE: Vec3 = Vec3::NEG_ONE;
const VEC3_NEG_X: Vec3 = Vec3::NEG_X;
const VEC3_NEG_Y: Vec3 = Vec3::NEG_Y;
const VEC3_NEG_Z: Vec3 = Vec3::NEG_Z;
const VEC4_ZERO: Vec4 = Vec4::ZERO;
const VEC4_ONE: Vec4 = Vec4::ONE;
const VEC4_NEG_ZERO: Vec4 = Vec4::ZERO;
const VEC4_NEG_ONE: Vec4 = Vec4::NEG_ONE;
const VEC4_NEG_X: Vec4 = Vec4::NEG_X;
const VEC4_NEG_Y: Vec4 = Vec4::NEG_Y;
const VEC4_NEG_Z: Vec4 = Vec4::NEG_Z;
const VEC4_NEG_W: Vec4 = Vec4::NEG_W;
fn new_vm(isolated: bool) -> StrafeluaGlobals {
let vm = Luau::new();
vm.sandbox(isolated).unwrap();
@ -45,27 +23,15 @@ trait Luavm {
StrafeluaGlobals {vm}
}
fn warn(&self) -> mlua::Function;
fn vector2(&self) -> mlua::Table;
fn vector3(&self) -> mlua::Table;
fn vector4(&self) -> mlua::Table;
}
trait Vectors {
fn arg(result: Option<mlua::Number>) -> f32;
}
impl Vectors for StrafeluaGlobals {
fn arg(result: Option<mlua::Number>) -> f32 {
match result {
Some(n) => n as f32,
None => 0.0 as f32,
}
}
fn warn(&self) -> Function;
fn vector2(&self) -> Table;
fn vector3(&self) -> Table;
fn vector4(&self) -> Table;
}
impl Luavm for StrafeluaGlobals {
//Debug stuff
fn warn(&self) -> mlua::Function {
fn warn(&self) -> Function {
return self.vm.create_function(|_, message: mlua::String| {
match Some(message) {
Some(lua_string) => cprintln!("<yellow>{}</yellow>", lua_string.to_str().unwrap()),
@ -75,32 +41,39 @@ impl Luavm for StrafeluaGlobals {
}).unwrap();
}
fn vector2(&self) -> mlua::Table {
fn vector2(&self) -> Table {
let zero = Vec2::ZERO;
let one = Vec2::ONE;
let neg_zero = Vec2::ZERO;
let neg_one = Vec2::NEG_ONE;
let neg_x = Vec2::NEG_X;
let neg_y = Vec2::NEG_Y;
let field_vector2 = self.vm.create_table().unwrap();
let vector2_one = self.vm.create_table().unwrap();
vector2_one.set("x", Self::VEC2_ONE.x).unwrap();
vector2_one.set("y", Self::VEC2_ONE.y).unwrap();
vector2_one.set("x", one.x).unwrap();
vector2_one.set("y", one.y).unwrap();
let vector2_zero = self.vm.create_table().unwrap();
vector2_zero.set("x", Self::VEC2_ZERO.x).unwrap();
vector2_zero.set("y", Self::VEC2_ZERO.y).unwrap();
vector2_zero.set("x", zero.x).unwrap();
vector2_zero.set("y", zero.y).unwrap();
let vector2_neg_zero = self.vm.create_table().unwrap();
vector2_neg_zero.set("x", Self::VEC2_NEG_ZERO.x).unwrap();
vector2_neg_zero.set("y", Self::VEC2_NEG_ZERO.y).unwrap();
vector2_neg_zero.set("x", neg_zero.x).unwrap();
vector2_neg_zero.set("y", neg_zero.y).unwrap();
let vector2_neg_one = self.vm.create_table().unwrap();
vector2_neg_one.set("x", Self::VEC2_NEG_ONE.x).unwrap();
vector2_neg_one.set("y", Self::VEC2_NEG_ONE.y).unwrap();
vector2_neg_one.set("x", neg_one.x).unwrap();
vector2_neg_one.set("y", neg_one.y).unwrap();
let vector2_neg_x = self.vm.create_table().unwrap();
vector2_neg_x.set("x", Self::VEC2_NEG_X.x).unwrap();
vector2_neg_x.set("y", Self::VEC2_NEG_X.y).unwrap();
vector2_neg_x.set("x", neg_x.x).unwrap();
vector2_neg_x.set("y", neg_x.y).unwrap();
let vector2_neg_y = self.vm.create_table().unwrap();
vector2_neg_y.set("x", Self::VEC2_NEG_Y.x).unwrap();
vector2_neg_y.set("y", Self::VEC2_NEG_Y.y).unwrap();
vector2_neg_y.set("x", neg_y.x).unwrap();
vector2_neg_y.set("y", neg_y.y).unwrap();
field_vector2.set("ONE", vector2_one).unwrap();
field_vector2.set("ZERO", vector2_zero).unwrap();
@ -110,8 +83,14 @@ impl Luavm for StrafeluaGlobals {
field_vector2.set("NEG_Y", vector2_neg_y).unwrap();
field_vector2.set("new", self.vm.create_function(|this: &Luau, (x,y): (Option<mlua::Number>, Option<mlua::Number>)| {
let vec2_x = <StrafeluaGlobals as Vectors>::arg(x);
let vec2_y = Vectors::arg(y);
let vec2_x = match x {
Some(n) => n as f32,
None => 0.0 as f32,
};
let vec2_y = match y {
Some(n) => n as f32,
None => 0.0 as f32,
};
let glam_vec = Vec2::new(vec2_x,vec2_y);
let vec2 = this.create_table().unwrap();
vec2.set("x", glam_vec.x).unwrap();
@ -123,43 +102,45 @@ impl Luavm for StrafeluaGlobals {
return field_vector2
}
fn vector3(&self) -> mlua::Table {
fn vector3(&self) -> Table {
let zero = Vec3::ZERO;
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 vector3_one = self.vm.create_table().unwrap();
vector3_one.set("x", Self::VEC3_ONE.x).unwrap();
vector3_one.set("y", Self::VEC3_ONE.y).unwrap();
vector3_one.set("z", Self::VEC3_ONE.z).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", Self::VEC3_ZERO.x).unwrap();
vector3_zero.set("y", Self::VEC3_ZERO.y).unwrap();
vector3_zero.set("z", Self::VEC3_ZERO.z).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", Self::VEC3_NEG_ZERO.x).unwrap();
vector3_neg_zero.set("y", Self::VEC3_NEG_ZERO.y).unwrap();
vector3_neg_zero.set("z", Self::VEC3_NEG_ZERO.z).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", Self::VEC3_NEG_ONE.x).unwrap();
vector3_neg_one.set("y", Self::VEC3_NEG_ONE.y).unwrap();
vector3_neg_one.set("z", Self::VEC3_NEG_ONE.z).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", Self::VEC3_NEG_X.x).unwrap();
vector3_neg_x.set("y", Self::VEC3_NEG_X.y).unwrap();
vector3_neg_x.set("z", Self::VEC3_NEG_X.z).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", Self::VEC3_NEG_Y.x).unwrap();
vector3_neg_y.set("y", Self::VEC3_NEG_Y.y).unwrap();
vector3_neg_x.set("z", Self::VEC3_NEG_Y.z).unwrap();
let vector3_neg_z = self.vm.create_table().unwrap();
vector3_neg_z.set("x", Self::VEC3_NEG_Z.x).unwrap();
vector3_neg_z.set("y", Self::VEC3_NEG_Z.y).unwrap();
vector3_neg_z.set("z", Self::VEC3_NEG_Z.z).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();
@ -167,12 +148,20 @@ impl Luavm for StrafeluaGlobals {
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();
field_vector3.set("NEG_Z", vector3_neg_z).unwrap();
field_vector3.set("new", self.vm.create_function(|this: &Luau, (x,y,z): (Option<mlua::Number>, Option<mlua::Number>, Option<mlua::Number>)| {
let vec3_x = vector_arg(x);
let vec3_y = vector_arg(y);
let vec3_z = vector_arg(z);
let vec3_x = match x {
Some(n) => n as f32,
None => 0.0 as f32,
};
let vec3_y = match y {
Some(n) => n as f32,
None => 0.0 as f32,
};
let vec3_z = match z {
Some(n) => n as f32,
None => 0.0 as f32,
};
let glam_vec = Vec3::new(vec3_x,vec3_y,vec3_z);
let vec3 = this.create_table().unwrap();
vec3.set("x", glam_vec.x).unwrap();
@ -184,56 +173,51 @@ impl Luavm for StrafeluaGlobals {
return field_vector3;
}
fn vector4(&self) -> mlua::Table {
fn vector4(&self) -> Table {
let zero = Vec4::ZERO;
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 vector4_one = self.vm.create_table().unwrap();
vector4_one.set("x", Self::VEC4_ONE.x).unwrap();
vector4_one.set("y", Self::VEC4_ONE.y).unwrap();
vector4_one.set("z", Self::VEC4_ONE.z).unwrap();
vector4_one.set("w", Self::VEC4_ONE.w).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", Self::VEC4_ZERO.x).unwrap();
vector4_zero.set("y", Self::VEC4_ZERO.y).unwrap();
vector4_zero.set("z", Self::VEC4_ZERO.z).unwrap();
vector4_zero.set("w", Self::VEC4_ZERO.w).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", Self::VEC4_NEG_ZERO.x).unwrap();
vector4_neg_zero.set("y", Self::VEC4_NEG_ZERO.y).unwrap();
vector4_neg_zero.set("z", Self::VEC4_NEG_ZERO.z).unwrap();
vector4_neg_zero.set("w", Self::VEC4_NEG_ZERO.w).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", Self::VEC4_NEG_ONE.x).unwrap();
vector4_neg_one.set("y", Self::VEC4_NEG_ONE.y).unwrap();
vector4_neg_one.set("z", Self::VEC4_NEG_ONE.z).unwrap();
vector4_neg_one.set("w", Self::VEC4_NEG_ONE.w).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", Self::VEC4_NEG_X.x).unwrap();
vector4_neg_x.set("y", Self::VEC4_NEG_X.y).unwrap();
vector4_neg_x.set("z", Self::VEC4_NEG_X.z).unwrap();
vector4_neg_x.set("w", Self::VEC4_NEG_X.w).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", Self::VEC4_NEG_Y.x).unwrap();
vector4_neg_y.set("y", Self::VEC4_NEG_Y.y).unwrap();
vector4_neg_x.set("z", Self::VEC4_NEG_Y.z).unwrap();
vector4_neg_x.set("w", Self::VEC4_NEG_Y.w).unwrap();
let vector4_neg_z = self.vm.create_table().unwrap();
vector4_neg_z.set("x", Self::VEC4_NEG_Z.x).unwrap();
vector4_neg_z.set("y", Self::VEC4_NEG_Z.y).unwrap();
vector4_neg_z.set("z", Self::VEC4_NEG_Z.z).unwrap();
vector4_neg_z.set("w", Self::VEC4_NEG_Z.w).unwrap();
let vector4_neg_w = self.vm.create_table().unwrap();
vector4_neg_w.set("x", Self::VEC4_NEG_W.x).unwrap();
vector4_neg_w.set("y", Self::VEC4_NEG_W.y).unwrap();
vector4_neg_w.set("z", Self::VEC4_NEG_W.z).unwrap();
vector4_neg_w.set("w", Self::VEC4_NEG_W.w).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();
@ -241,14 +225,24 @@ impl Luavm for StrafeluaGlobals {
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();
field_vector4.set("NEG_Z", vector4_neg_z).unwrap();
field_vector4.set("NEG_W", vector4_neg_w).unwrap();
let new_vector4 = self.vm.create_function(|this: &Luau, (x,y,z,w): (Option<mlua::Number>, Option<mlua::Number>, Option<mlua::Number>, Option<mlua::Number>)| {
let vec4_x = vector_arg(x);
let vec4_y = vector_arg(y);
let vec4_z = vector_arg(z);
let vec4_w = vector_arg(w);
let vec4_x = match x {
Some(n) => n as f32,
None => 0.0 as f32,
};
let vec4_y = match y {
Some(n) => n as f32,
None => 0.0 as f32,
};
let vec4_z = match z {
Some(n) => n as f32,
None => 0.0 as f32,
};
let vec4_w = match w {
Some(n) => n as f32,
None => 0.0 as f32,
};
let glam_vec = Vec4::new(vec4_x,vec4_y,vec4_z,vec4_w);
let vec4 = this.create_table().unwrap();
vec4.set("x", glam_vec.x).unwrap();