Game Development Reference
In-Depth Information
message = "Hello World"
print(message)
What we have just done here is assign the string "Hello World" to the message variable; then we use
the print function to display the value of message in the terminal.
Just like strings, we can also print numbers, and the simplest way to do so is
print(5)
age = 1
print(age)
print("Age :", age)
print(1,2,3,4,5,"One")
The aim of this is to demonstrate that using print , we can display variables, numbers, and strings to
the terminal.
Strings
Strings in Lua can be enclosed in single or double quotes. So, for example, both 'Lua' and "Lua"
are valid. Literal strings can be used in a manner similar to C by preceding them with a blackslash
( \ ) and enclosing them in the single or double quotes. These can be used to include commonly used
escape sequences such as \b , \t , \v , \r , \n , \\ , \' , and \" . They can also be used to specify a
numeric value with the format \ddd , where d is a digit.
print("\65")
There are times when you want to include chunks of text, and keeping track of the quotation marks
can sometimes get a bit tricky, especially when trying to get them to match and line up. In such
cases, you can use the long-bracket format, by which you enclose the text within [[ and ]] . Here's
an example:
message = [[That's "Jack O'Neill", with two ll's]]
If you used single quotes for enclosure in a scenario like this, you would get an error:
message = 'That's "Jack O'Neill", with two ll's'
Likewise, you would also get an error using the following line, as the single and double quotes need
to have a matching pair or be escaped.
message = "That's "Jack O'Neill", with two ll's"
The correct way to declare the same would be to place a backslash before the literal quotes, like this:
message = 'That\'s "Jack O\'Neill", with two ll\'s'
or like this:
message = "That's \"Jack O'Neill\", with two ll's"
 
Search WWH ::




Custom Search