life is forming
This commit is contained in:
parent
57d0d3c421
commit
7a4fa8c13c
@ -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
|
||||
|
@ -8,4 +8,6 @@ mod rc;
|
||||
#[path = "./luau/vm.rs"]
|
||||
mod vm;
|
||||
#[path = "./luau/alias.rs"]
|
||||
mod alias;
|
||||
mod alias;
|
||||
#[path = "./luau/terminal.rs"]
|
||||
mod terminal;
|
47
src/luau/terminal.rs
Normal file
47
src/luau/terminal.rs
Normal file
@ -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<String> {
|
||||
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<Table>;
|
||||
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<Table> {
|
||||
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(())
|
||||
}
|
||||
}
|
@ -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)?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user