A way for print to output arguments on the same line

As a Roblox developer it is extremely difficult to output values on the same line for debugging purposes. The print function can take multiple arguments, however this doesn’t give the behaviour I would like, and there are times, mostly in loops, where you want to print values in a table, something like this.

for i, v in ipairs({ "a", "b", "c" }) do
    print(v)
end

And they’re all printed on a new line. It would be nice if a separate function was added like C’s printf (well not f for the formatting, just a function that takes the fact that it doesn’t add new lines) or just Lua’s io.write.

If such a function is added it would improve the debugging experience for the sake of cleanliness.

2 Likes

You can already get this behavior in several ways:

local tab = {"a", "b", "c"}
print(table.unpack(tab))

or

local tab = {"a", "b", "c"}
print(table.concat(tab, ", "))
4 Likes

I would prefer direct support but this can work as well, also table.concat doesn’t work for non-string values, what if I have booleans in there or tables with __tostring etc, and unpack stops at a nil value

1 Like

This is an unlikely feature request given it involves modifying the core of the language, and that the print function just outputs a tostring of the table.

Use meta tables or a ‘util function’ to do this for you… or one of the above solitons; unpacking is exactly what you want.

2 Likes

How is modifying the core of the language? All I would like to see is a function that doesnt implicitly add a new line. Plus, Roblox has quite literally made a brand new VM, and new language at this point (hence Luau). So why should just no implicit newlines modify the core of Lua(u), but completely new syntax and such isn’t?

How do I, without concatenating all the numbers to one string, print all these numbers in one line without print spamming newlines:

for i = 1, 10 do
    print(i)
end
7 Likes