From cb52ce8de093560a69238f2a307192c82a1de16a Mon Sep 17 00:00:00 2001 From: GhostedGaming Date: Tue, 24 Dec 2024 13:09:20 -0500 Subject: [PATCH] Imported the whole library and now we have alot more functtions (sorry caz) --- engine/src/core/repl/zlua.rs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/engine/src/core/repl/zlua.rs b/engine/src/core/repl/zlua.rs index da3770e..c5c483b 100644 --- a/engine/src/core/repl/zlua.rs +++ b/engine/src/core/repl/zlua.rs @@ -1,5 +1,4 @@ -use rand::Rng; -use mlua::{Function, Lua, MultiValue, Number, Value::Nil}; +use mlua::{Function, Lua, LuaOptions, MultiValue, Number, Value::Nil}; use rustyline::{error::ReadlineError, DefaultEditor}; use crate::core::repl::handler::Command; @@ -10,7 +9,10 @@ impl Command for ZLua { fn execute(&self, _args: Option>) -> Result<(), anyhow::Error> { let time = chrono::Local::now().format("%H:%M:%S.%3f").to_string(); let prompt = format!("[{}/{}] {}", time, "ZLUA", ">>\t"); - let lua = Lua::new(); + let lua = Lua::new_with( + mlua::StdLib::ALL_SAFE, + LuaOptions::default() + )?; let globals = lua.globals(); //This just adds 2 numbers together let add = lua.create_function(|_, (number1,number2):(i32,i32)|{ @@ -28,22 +30,12 @@ impl Command for ZLua { })?; globals.set("is_equal", is_equal)?; - //This is just true or false let log = lua.create_function(|_, (msg,): (String,)| { - println!("{}", msg); - Ok(()) + println!("{}", msg); + Ok(()) })?; globals.set("log", log)?; - let if_statement = lua.create_function(|_, (condition, then_value, else_value): (bool, String, String)| { - if condition { - println!("{}", then_value); - } else { - println!("{}", else_value); - } - Ok(()) - })?; - globals.set("if_then", if_statement)?; let mut editor = DefaultEditor::new().expect("Failed to create editor");