Lua doesn’t require any structure so we can just write what we want to execute. Like this:
but also we can use parenthesis if we want to
Additional, not visible effect of using print to output something on the screen is that the newline is automatically added ad the end so we don’t have to do it ourself.
There’s also a module (not sure if that’s Lua nomenclature) io which also can be used. There’s a write method that does the same with a small modification
This way we can get rid of the default newline character that was added in the previous two examples of printing.
There are few differences between print and io.write. The first is what we already know – write gives a bit more control over what is printed – nothing gets added by default. The second one is that write uses currently opened stream. So if we write like this:
we will get a file called output.txt with HelloLua. Nice.
So we have learned how to get text printed to the screen or file.