[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

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."


See Also ...

Lua keywords/topics

assignment
break
comments
data types
do
for (generic)
for (numeric)
function
identifiers
if / then / else
keywords
local
logical operators
precedence
relational operators
repeat
return
tables
while

Topics

Lua base functions
Lua bc (big number) functions
Lua bit manipulation functions
Lua coroutine functions
Lua debug functions
Lua io functions
Lua LPEG library
Lua math functions
Lua os functions
Lua package functions
Lua PCRE regular expression functions
Lua script extensions
Lua SQLite (database) interface
Lua string functions
Lua syntax
Lua table functions
Lua utilities
Scripting
Scripting callbacks - plugins

(Help topic: lua=string literals)

Documentation contents page


Search ...

Enter a search string to find matching documentation.

Search for:   

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]