lune/crates/lune-std/src/globals/print.rs
2025-04-23 15:20:53 +02:00

19 lines
605 B
Rust

use std::io::Write;
use lune_utils::fmt::{pretty_format_multi_value, ValueFormatConfig};
use mlua::prelude::*;
const FORMAT_CONFIG: ValueFormatConfig = ValueFormatConfig::new()
.with_max_depth(4)
.with_colors_enabled(true);
pub fn create(lua: Lua) -> LuaResult<LuaValue> {
let f = lua.create_function(|_: &Lua, args: LuaMultiValue| {
let formatted = format!("{}\n", pretty_format_multi_value(&args, &FORMAT_CONFIG));
let mut stdout = std::io::stdout();
stdout.write_all(formatted.as_bytes())?;
stdout.flush()?;
Ok(())
})?;
f.into_lua(&lua)
}