This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
andrewsams's profile picture

Lua Prompt Providing Additional Output with print()

Started by andrewsams, 13 February 2014 - 04:05 PM
andrewsams #1
Posted 13 February 2014 - 05:05 PM
So if I invoke the print() function at the Lua prompt, I get what I expect to be displayed, but I also get a 1 on the following line of output. Is this a return value of 'true'?

Ex: print("Hello!")

Output:
Hello!
1

Can I suppress that second line of output (the 1) from displaying on the Lua prompt?
Lyqyd #2
Posted 13 February 2014 - 05:12 PM
What's going on here is twofold:

The print call writes a line to the screen.
The print call returns the number of lines it wrote. The Lua prompt prints the return value of the function (1).

You cannot suppress that output using the normal print function (nor should you want to), but if you really don't want to see that, you could use another function that wraps the print function and discards its return value:


function lprint(...)
  print(...)
end
andrewsams #3
Posted 13 February 2014 - 10:44 PM
Most excellent, thank you for your time and expertise.