Example: Hello World in Lua
The following Lua code displays/outputs a string data type.
print ("Hello, World!")
Output:
Hello, World!
Example: Numbers in Lua
The following Lua code displays/outputs integer data types.
print (10)
print (10+10)
Output:
10
20
Lua is a dynamically typed language. As such, variables do not have types - only values do (all values carry their own type).
Example: Concatenation in Lua
The following code shows how to perform Concatenation (i.e. joining two things together) in Lua.
age = 44
print ("Hello. I am " .. age .. " years old.")
print ("Hello. I am " .. 55 .. " years old.")
print ("Hello. I am ", 56, " years old.")
Output:
Hello. I am 44 years old.
Hello. I am 55 years old.
Hello. I am 56 years old.
Example: New line escape character
print ("Line1\nLine2\nLine3")
Output:
Line1
Line2
Line3
Example: Escaping double quotes so they can be displayed
print ("I am saying \"Hello\" in Lua")
Output:
I am saying "Hello" in Lua