Literals and output in Lua
- Screen output is done with the command print.
- There are brackets around the parameters.
- Multiple parameter are separated by commas.
- Strings are defined with ' and ".
Test-Programm print_1.lua
print ('1: Hello World') print ("2: Hello World")
The Result:
1: Hello World 2: Hello World
New lines
Test-Programm print_2a.lua
print ( '1: Hello\ World' ) print ( "2: Hello\ World" )
The Result:
1: Hello World 2: Hello World
Test-Programm print_2b.lua
print ( '5: Hello\n World' ) print ( "6: Hello\n World" )
The Result:
5: Hello World 6: Hello World
Alternative String definition
You can define Strings also with [ [ and ] ].
Test-Programm print_3a.lua
print [[Hello World]]
The Result:
Hello World
Test-Programm print_3b.lua
print [[Hello World, you are so nice today.]]
The Result:
Hello World, you are so nice today.
- Multiple lines are possible.
Test-Programm print_3c.lua
print [[ Hello World, you are so nice today.]]
The Result:
Hello World, you are so nice today.
- A new-line after [[ is ignored.
Test-Programm print_4_en.lua
print [[ Hello World, how [[nice]] are you today]]
The Result:
Hello World, how [[nice]] are you today
- The square braces may be nested.
Special Characters
Each character can be created with \ and the octal representation1of the ASCII-value.
Named characters
Each character can be created with \ and the following short cut.
Character | Function | Shortcut |
\a | PC-Sound | BEL |
\b | Backspace | BS |
\f | Form Feed | FF |
\n | New line | LF |
\r | carriage return | CR |
\t | (horizontal) tabular | HT |
\v | vertical tabular | VT |
\ | Backslash | |