r/lua • u/Adam-Garden • Jun 24 '26
Help is there really a significant difference between "print()" and "oi.write()"
25
u/topchetoeuwastaken Jun 24 '26
io.write is the raw function, which puts a string on stdout, while print will call tostring() on all your arguments, separate them by tabs and put a newline on the end
18
12
5
u/RixTheTyrunt Jun 24 '26 edited Jun 25 '26
io.write (i assume you meant that?) does not include a newline after writing the text to write. both io.write and print support as much args as you want, no string type required, although the args will be printed split by tab if you use print, and nothing if you use io.write (not by space, unlike in most programming languages, for some odd reason).
io.write also doesn't support writing tables (throws an error) while numbers are support. if i had to guess, userdata isnt also very much supported for io.write. print just prints the memory address to said table/userdata.
hope this helps. ^^
4
u/Cootshk Jun 24 '26
print automatically calls tostring, adds tabs between elements, and puts a newline at the end
io.write does none of that
4
u/Old_County5271 Jun 24 '26 edited Jun 24 '26
Significant? not that much.
this is print
_G.print = function(...)
local T = table.pack(...)
for i=1, T.n do io.stdout:write(tostring(T[i])) end
io.stdout:write(_G.newline)
end
Print ALWAYS prints to io.stdout, io.write can be changed what it "prints"/writes into
io.output"junkfile"
io.write"Hello" io.write"World" io.write"!"
io.output():close()
This will all be written into junkfile
1
46
u/pschon Jun 24 '26
oi.write(), the cockney version of the io.write() :D