diff --git a/Cargo.toml b/Cargo.toml index 665d50d..983f847 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,9 @@ mlua = { version = "0.10.0", features = ["luau-jit"] } thiserror = "2.0.9" uzers = "0.12.1" whoami = "1.5.2" + +[profile.release] +strip = true +opt-level = "s" +lto = true +codegen-units = 1 diff --git a/src/lib.rs b/src/lib.rs index 38f1e24..14a6294 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,4 +8,6 @@ mod rc; #[path = "./luau/vm.rs"] mod vm; #[path = "./luau/alias.rs"] -mod alias; \ No newline at end of file +mod alias; +#[path = "./luau/terminal.rs"] +mod terminal; \ No newline at end of file diff --git a/src/luau/terminal.rs b/src/luau/terminal.rs new file mode 100644 index 0000000..5c9fe94 --- /dev/null +++ b/src/luau/terminal.rs @@ -0,0 +1,47 @@ +use mlua::{Result as lResult, Table}; +use crossterm::style::Stylize; +use crate::vm::Vm; + +macro_rules! term_colors_luau { + ($self:expr, $colors_table:expr, $($color:ident)+) => { + $( + let $color = $self.0.create_function(|_this, text: String| -> lResult { + Ok(text.$color().to_string()) + })?; + $colors_table.set(stringify!($color).to_ascii_uppercase(), $color)?; + )+ + }; +} + +pub trait TerminalColors { + fn var_terminal_colors(&self, colors_table: &Table) -> lResult<()>; + fn var_terminal_style(&self) -> lResult; + fn var_terminal(&self) -> lResult<()>; +} +impl TerminalColors for Vm { + fn var_terminal_colors(&self, colors_table: &Table) -> lResult<()> { + term_colors_luau!(self, colors_table, + grey black dark_grey red + dark_red green dark_green yellow + dark_yellow blue dark_blue magenta + dark_magenta cyan dark_cyan white + ); + Ok(()) + } + + fn var_terminal_style(&self) -> lResult
{ + let color_table = self.0.create_table()?; + let style = self.0.create_table()?; + self.var_terminal_colors(&style)?; + color_table.set("STYLE", &style)?; + Ok(color_table) + } + + fn var_terminal(&self) -> lResult<()> { + let term_table = self.0.create_table()?; + let style_table = self.var_terminal_style()?; + term_table.set("OUT", style_table)?; + self.0.globals().set("TERMINAL", &term_table)?; + Ok(()) + } +} \ No newline at end of file diff --git a/src/luau/vm.rs b/src/luau/vm.rs index 683a5b7..e5aed0e 100644 --- a/src/luau/vm.rs +++ b/src/luau/vm.rs @@ -1,9 +1,10 @@ -use crate::VERSION; use mlua::{ Lua as Luau, Result as lResult, MultiValue, }; +use crate::VERSION; +use crate::terminal::TerminalColors; use core::fmt; use color_print::cprintln; @@ -58,7 +59,7 @@ impl Globals for Vm { } } -pub struct Vm(Luau); +pub struct Vm(pub Luau); impl Vm { pub fn new() -> Self { Self(Luau::new()) @@ -68,6 +69,7 @@ impl Vm { self.print()?; self.printraw()?; self.version()?; + self.var_terminal()?; self.0.globals().set("getfenv", mlua::Nil)?; self.0.globals().set("setfenv", mlua::Nil)?; self.0.sandbox(true)?;