Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a way to replicate io.write in Roblox?

Asked by 4 years ago
Edited 4 years ago

For those of you that are unfamiliar with Lua outside of Roblox's environment, io.write is a Lua function that takes a variable amount of arguments, and prints them to the current output file.

However, unlike print, it does not delimit its arguments with tabs, it doesn't call tostring on its arguments, and there is no implicit newline appending.

Here is a demonstration of io.write

io.write("Hello world")
io.write("Goodbye world")

yields

Hello worldGoodbye world

It doesn't implicitly add a newline, to combat this, you would append it yourself.

io.write("Hello world\n")
io.write("This is in a new line now\n")

yields

Hello world

This is in a new line now

And if write receives a non-string, non-number argument:

io.write({})

yields an exception with the following message

bad argument #1 to 'write' (string expected, got table)

Ok back to my question

I would like to use io.write as it would let me do this without needing to concatenate everything into a single string only to print it:

for i = 0, 19 do
    -- just an example
    io.write(i, ' ')
end
io.write('\n')
-- blah blah blah

Output: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Also it would let me write printf ;)

-- simple google search will suffice to explain printf if you don't know how it works

local function printf(s, ...)
    local formatted = s:format(...)
    io.write(formatted)
    return #formatted
end

local n = math.random(0, 9)

printf("Number: %d", n)

I really just want it for the fact that it doesn't append any newlines

PLEASE: Only answer if you know what you're talking about.

0
Don't quote me on it, but I don't think it's possible. Roblox only gives us stuff like print, warn, and error for managing the output log. Hacreey 49 — 4y
0
To add, you could always write a module that displays itself in a custom-made interface/log that has the same functionality as io. Hacreey 49 — 4y
0
Of course you could, but is it practical at all? No. @mrmcmuffinz123 crywink 419 — 4y

Answer this question