diff --git a/crates/lune-std-stdio/src/lib.rs b/crates/lune-std-stdio/src/lib.rs index 3c7c487..a4f7751 100644 --- a/crates/lune-std-stdio/src/lib.rs +++ b/crates/lune-std-stdio/src/lib.rs @@ -1,5 +1,6 @@ #![allow(clippy::cargo_common_metadata)] +use lune_utils::fmt::{pretty_format_multi_value, ValueFormatConfig}; use mlua::prelude::*; use mlua_luau_scheduler::LuaSpawnExt; @@ -13,6 +14,10 @@ mod style_and_color; use self::prompt::{prompt, PromptOptions, PromptResult}; use self::style_and_color::{ColorKind, StyleKind}; +const FORMAT_CONFIG: ValueFormatConfig = ValueFormatConfig::new() + .with_max_depth(4) + .with_colors_enabled(false); + /** Creates the `stdio` standard library module. @@ -40,9 +45,8 @@ fn stdio_style(lua: &Lua, style: StyleKind) -> LuaResult { style.ansi_escape_sequence().into_lua(lua) } -fn stdio_format(_: &Lua, _args: LuaMultiValue) -> LuaResult { - // TODO: Migrate from old crate - unimplemented!() +fn stdio_format(_: &Lua, args: LuaMultiValue) -> LuaResult { + Ok(pretty_format_multi_value(&args, &FORMAT_CONFIG)) } async fn stdio_write(_: &Lua, s: LuaString<'_>) -> LuaResult<()> { diff --git a/crates/lune-std/src/globals/print.rs b/crates/lune-std/src/globals/print.rs index 45ccdab..3b8d5f1 100644 --- a/crates/lune-std/src/globals/print.rs +++ b/crates/lune-std/src/globals/print.rs @@ -1,8 +1,18 @@ +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 { let f = lua.create_function(|_, args: LuaMultiValue| { - // TODO: Port this over from the old crate + 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) diff --git a/crates/lune-std/src/globals/warn.rs b/crates/lune-std/src/globals/warn.rs index 45ccdab..ee42ddb 100644 --- a/crates/lune-std/src/globals/warn.rs +++ b/crates/lune-std/src/globals/warn.rs @@ -1,8 +1,22 @@ +use std::io::Write; + +use lune_utils::fmt::{pretty_format_multi_value, Label, ValueFormatConfig}; use mlua::prelude::*; +const FORMAT_CONFIG: ValueFormatConfig = ValueFormatConfig::new() + .with_max_depth(4) + .with_colors_enabled(true); + pub fn create(lua: &Lua) -> LuaResult { let f = lua.create_function(|_, args: LuaMultiValue| { - // TODO: Port this over from the old crate + let formatted = format!( + "{}\n{}\n", + Label::Warn, + 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)