forked from StrafesNET/strafe-client
Compare commits
No commits in common. "5327b201c7fa6c5de2beafd319c2df216609c6b5" and "6e703075e9c84cd5c57b76741506d2d3b2d59e36" have entirely different histories.
5327b201c7
...
6e703075e9
58
src/luau.rs
58
src/luau.rs
@ -1,58 +0,0 @@
|
|||||||
use mlua::{Lua as Luau, Result, Table};
|
|
||||||
use glam::Vec3;
|
|
||||||
|
|
||||||
struct StrafeluaGlobals<'a> {
|
|
||||||
current_vm: &'a Luau
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> StrafeluaGlobals<'a> {
|
|
||||||
fn new_vm(current_vm: &'a Luau) -> Self {
|
|
||||||
Self {current_vm}
|
|
||||||
}
|
|
||||||
fn strafe_player(&self) -> Table {
|
|
||||||
let main_table = &self.current_vm.create_table().unwrap();
|
|
||||||
main_table.clone()
|
|
||||||
}
|
|
||||||
fn vector3(&self) -> Table<'a> {
|
|
||||||
let vec3 = &self.current_vm.create_table().unwrap();
|
|
||||||
|
|
||||||
|
|
||||||
// self.current_vm.create_function(|vm, (x,y,z): (f32,f32,f32)| {
|
|
||||||
// let vec = Vec3::new(x,y,z);
|
|
||||||
// vec3.set("x", vec.x).unwrap();
|
|
||||||
// vec3.set("y", vec.y).unwrap();
|
|
||||||
// vec3.set("z", vec.z).unwrap();
|
|
||||||
// Ok(vec3)
|
|
||||||
// }).unwrap();
|
|
||||||
|
|
||||||
return vec3.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_state() -> Result<Luau> {
|
|
||||||
let vm = Luau::new();
|
|
||||||
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();
|
|
||||||
|
|
||||||
let strafe_globals = StrafeluaGlobals::new_vm(&vm);
|
|
||||||
|
|
||||||
let strafe_player = strafe_globals.strafe_player();
|
|
||||||
let strafe_vector3 = strafe_globals.vector3();
|
|
||||||
vm.globals().set("Player", strafe_player).unwrap();
|
|
||||||
vm.globals().set("Vector3", strafe_vector3).unwrap();
|
|
||||||
|
|
||||||
let gib = *strafe_globals.current_vm;
|
|
||||||
let _ = vm.load(r#"
|
|
||||||
type f64 = number
|
|
||||||
type vec3 = (x: f64, y: f64, z: f64) -> {x: f64, y: f64, z: f64}
|
|
||||||
local Vector3: vec3 = Vector3
|
|
||||||
|
|
||||||
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))
|
|
||||||
"#).exec();
|
|
||||||
|
|
||||||
Ok(gib)
|
|
||||||
}
|
|
@ -1,6 +1,5 @@
|
|||||||
mod bvh;
|
mod bvh;
|
||||||
mod aabb;
|
mod aabb;
|
||||||
mod luau;
|
|
||||||
mod model;
|
mod model;
|
||||||
mod setup;
|
mod setup;
|
||||||
mod window;
|
mod window;
|
||||||
@ -118,7 +117,5 @@ pub fn default_models()->model::IndexedModelInstances{
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main(){
|
fn main(){
|
||||||
luau::new_state().expect("Failed to load strafe lua");
|
|
||||||
|
|
||||||
setup::setup_and_start(format!("Strafe Client v{}",env!("CARGO_PKG_VERSION")));
|
setup::setup_and_start(format!("Strafe Client v{}",env!("CARGO_PKG_VERSION")));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user