feat: support multiple arguments in pprint #138

Merged
Usielrivas merged 1 commit from main into main 2026-01-18 20:11:59 +00:00
Usielrivas commented 2026-01-15 19:11:37 +00:00 (Migrated from github.com)

This change makes pprint behave like Lua’s print, supporting multiple arguments and printing them in a single call with the same semantics.

This change makes pprint behave like Lua’s print, supporting multiple arguments and printing them in a single call with the same semantics.
ElhamAryanpur commented 2026-01-18 20:05:06 +00:00 (Migrated from github.com)

Thank you so much! This is very helpful. Let me check, I think we can use Rust's print! directly without needing to store the values in a Vec

Thank you so much! This is very helpful. Let me check, I think we can use Rust's print! directly without needing to store the values in a Vec
ElhamAryanpur commented 2026-01-18 20:11:44 +00:00 (Migrated from github.com)

like this:

pub fn pprint(lua: &mlua::Lua) -> mlua::Result<()> {
    lua.globals().set(
        "astra_internal__pretty_print",
        lua.create_function(|_, args: mlua::MultiValue| {
            for input in args {
                if let Some(s) = input.as_string() {
                    print!("{} ", s.to_string_lossy());
                } else if input.is_userdata() {
                    print!("{input:?} ")
                } else {
                    print!("{input:#?} ")
                };
            }

            Ok(())
        })?,
    )
}
like this: ```rs pub fn pprint(lua: &mlua::Lua) -> mlua::Result<()> { lua.globals().set( "astra_internal__pretty_print", lua.create_function(|_, args: mlua::MultiValue| { for input in args { if let Some(s) = input.as_string() { print!("{} ", s.to_string_lossy()); } else if input.is_userdata() { print!("{input:?} ") } else { print!("{input:#?} ") }; } Ok(()) })?, ) } ```
Sign in to join this conversation.
No description provided.