From d694fa1eb9a87a6a1a0412b97c9190f66ef5e676 Mon Sep 17 00:00:00 2001 From: Chance Date: Sat, 22 Mar 2025 19:19:02 -0400 Subject: [PATCH] deprecate and remove zlua --- engine/Cargo.toml | 1 - engine/src/core/repl/commands.rs | 7 +- engine/src/core/repl/mod.rs | 4 +- engine/src/core/repl/zlua.rs | 119 ------------------------------- engine/src/main.rs | 2 +- 5 files changed, 4 insertions(+), 129 deletions(-) delete mode 100644 engine/src/core/repl/zlua.rs diff --git a/engine/Cargo.toml b/engine/Cargo.toml index 2321790..bed0ef4 100644 --- a/engine/Cargo.toml +++ b/engine/Cargo.toml @@ -13,7 +13,6 @@ dirs-next = "2.0.0" lazy_static.workspace = true log = "0.4.22" -mlua = { version = "0.10.2", features = ["anyhow", "lua54", "vendored"] } once_cell = "1.20.2" parking_lot.workspace = true regex = "1.11.1" diff --git a/engine/src/core/repl/commands.rs b/engine/src/core/repl/commands.rs index 861785d..8eff6ca 100644 --- a/engine/src/core/repl/commands.rs +++ b/engine/src/core/repl/commands.rs @@ -1,12 +1,9 @@ use std::{fs, path::PathBuf, str::FromStr}; use anyhow::anyhow; -use colored::Colorize; -use mlua::prelude::*; -use mlua::{Lua, MultiValue}; + use parking_lot::RwLock; use regex::Regex; -use rustyline::{DefaultEditor, error::ReadlineError}; use super::{handler::Command, input::tokenize}; use crate::core::repl::handler::COMMAND_MANAGER; @@ -36,7 +33,7 @@ impl Command for HelpCommand { } } Ok(()) - } + } fn undo(&self) {} diff --git a/engine/src/core/repl/mod.rs b/engine/src/core/repl/mod.rs index 3e029fa..c850436 100644 --- a/engine/src/core/repl/mod.rs +++ b/engine/src/core/repl/mod.rs @@ -5,7 +5,6 @@ use crate::commands; pub mod commands; pub mod handler; pub mod input; -pub mod zlua; pub fn setup() { commands!( @@ -14,7 +13,6 @@ pub fn setup() { ClearCommand, ExitCommand, CounterCommand, - PanicCommmand, - zlua::ZLua + PanicCommmand ); } diff --git a/engine/src/core/repl/zlua.rs b/engine/src/core/repl/zlua.rs deleted file mode 100644 index e895d85..0000000 --- a/engine/src/core/repl/zlua.rs +++ /dev/null @@ -1,119 +0,0 @@ -use mlua::{Lua, LuaOptions, MultiValue}; -use rustyline::{DefaultEditor, error::ReadlineError}; - -use crate::core::repl::handler::Command; - -#[derive(Default)] -pub struct ZLua; - -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_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)| { - let result = number1 + number2; - println!("{result}"); - Ok(()) - })?; - globals.set("add", add)?; - - let is_equal = lua.create_function(|_, (list1, list2): (i32, i32)| { - if list1 == 0 || list2 == 0 { - return Err(mlua::Error::RuntimeError( - "Zero values not allowed".to_string(), - )); - } - Ok(list1 == list2) - })?; - globals.set("isEqual", is_equal)?; - - let log = lua.create_function(|_, (msg,): (String,)| { - println!("{}", msg); - Ok(()) - })?; - globals.set("log", log)?; - - let fail_safe = lua.create_function(|_, ()| { - println!("Failed"); - Ok(()) - })?; - globals.set("failSafe", fail_safe)?; - let mut editor = DefaultEditor::new().expect("Failed to create editor"); - - loop { - let mut prompt = &prompt; - let mut line = String::new(); - - loop { - match editor.readline(prompt) { - Ok(input) => line.push_str(&input), - Err(ReadlineError::Interrupted) => { - println!("Exiting ZLUA shell..."); - return Ok(()); - } - Err(_) => {} - } - - match lua.load(&line).eval::() { - Ok(values) => { - for value in &values { - match value { - mlua::Value::Nil => println!("Got nil value"), - mlua::Value::Number(n) => println!("Got number: {}", n), - mlua::Value::String(s) => println!("Got string: {}", s.to_str()?), - mlua::Value::Boolean(b) => println!("Got boolean: {}", b), - _ => eprintln!("Got unexpected type: {:#?}", value), - } - } - editor.add_history_entry(line).unwrap(); - println!( - "{}", - values - .iter() - .map(|value| format!("{:#?}", value)) - .collect::>() - .join("\t") - ); - break; - } - Err(mlua::Error::SyntaxError { - incomplete_input: true, - .. - }) => { - // continue reading input and append it to `line` - line.push('\n'); // separate input lines - } - - Err(e) => { - eprintln!("Error: {} at line {}", e, line.lines().count()); - eprintln!("Input that caused error: {}", line); - break; - } - } - } - } - } - - fn undo(&self) {} - - fn redo(&self) {} - - fn get_description(&self) -> String { - String::from("Runs the ZLua interpreter") - } - - fn get_name(&self) -> String { - String::from("zlua") - } - - fn get_help(&self) -> String { - String::from("zlua") - } - - fn get_params(&self) -> String { - String::from("No parameters required.") - } -} diff --git a/engine/src/main.rs b/engine/src/main.rs index 13619b6..4ad7231 100644 --- a/engine/src/main.rs +++ b/engine/src/main.rs @@ -1,6 +1,6 @@ use core::{ panic::set_panic_hook, - repl::{handler::COMMAND_MANAGER, setup}, + repl::setup, splash, workspace, };