string literals

Literal strings (constants) are delimited by single or double quotes. Square brackets can also be used, as described below.

The same quote that starts the string ends it, allowing you to use the other quote inside the string, eg.
a = "Nick's cat"
b = 'Nick says "hello" to you'
You can also use certain "escape" sequences to imbed special characters:

\a	bell (0x07)
\b	backspace  (0x08)
\f	form feed (0x0C)
\n	newline  (0x0A)
\r	carriage return (0x0D)
\t	horizontal tab (0x09)
\v	vertical tab (0x0B)
\\	backslash
\"	double quote
\'	single quote
\[	left square bracket
\]	right square bracket
You can also imbed other codes by using \ddd where ddd is up to 3 decimal digits. For example:
a = "\027"  -- the "escape" character (hex 0x1B)
Be cautious if you do not use exactly three digits, because then another digit following the code might be considered to be part of it.

You can also use square brackets to make multiple-line strings, or strings with both sorts of quotes inside them. For example:
a = [[
Here you will experience your first full combat against MOBILES, also known
as MOBS. Mobile is the name used for monsters and the like in the game.
All exits, except down, lead to a CAGE mob. Some of these cage mobs may be
aggressive and will attack you upon entering their room. As you kill them,
you will gain experience, as well as academy equipment and gold.
]]
This sort of literal string ignores escape sequences. It also discards a newline if the first character is a newline (as in the example above).

If you might have two brackets inside the string you can use "=" signs to make strings which only match the same number of "=" signs at the end, for example:
a = [====[
Here you will experience your first full combat against MOBILES, also known
as MOBS. Mobile is the name used for monsters and the like in the game.
All exits, except down, lead to a CAGE mob. Some of these cage mobs may be
aggressive and will attack you upon entering their room. As you kill them,
you will gain experience, as well as academy equipment and gold.
]====]
Another way of doing multiple-line strings is to put a backslash at the end of the line, eg.
a = "Here you will experience your first full combat against MOBILES, also known \
as MOBS. Mobile is the name used for monsters and the like in the game. \
All exits, except down, lead to a CAGE mob. Some of these cage mobs may be \
aggressive and will attack you upon entering their room. As you kill them, \
you will gain experience, as well as academy equipment and gold."

Lua keyword/topics

Topics