First steps in Lua - Literals and OutputDeutsch


You are here:LuaHello World


Literals and output in Lua

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.

Test-Programm print_3c.lua
print [[
Hello World,
you are so nice today.]]
The Result:
Hello World,
you are so nice today.

Test-Programm print_4_en.lua
print [[
Hello World,
how [[nice]] are you today]]
The Result:
Hello World,
how [[nice]] are you today

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
single quote
\" double quote
\[ left square bracket
\] right square bracket

Test-Programm print_5.lua
--~ print ( "\a", "\a" )
--~ print ( "\b", "\b" )
--~ print ( "\f", "\f" )
--~ print ( "\n", "\n" )
--~ print ( "\r", "\r" )
--~ print ( "\"", "\"" )
--~ print ( "\v", "\v" )
print ( "\"", "\"" )
print ( "\", "\" )
print ( "\"", "\"" )
print ( "\[", "\[" )
print ( "\]", "\]" )
The Result:
\"	"
\	
\"	"
\[	[
\]	]