Literary strings [Lua 5.1]
So I started learning Lua (5.1) and I saw this thing called literal strings. And I have no idea what they are doing. The manual states that \ a is a bell, but when I type
print('hello\athere')
The IDE prints out a weird square labeled "bel". So if someone can help me and explain each of them [Literary lines]. that would be really helpful.
ps i am using Sublime Text 3
source to share
Only ASCII between 0x20
and 0x7E
printable characters . How other characters, including '\a'
and '\b'
, are displayed is implementation dependent.
'\a'
, ASCII 7
for BEL
, is for warning use. On output, a '\a'
Typical terminal would give an audible or visible warning. Your IDE decided to show a different result than the warning. This is ok since it is up to implementation.
source to share
These sequences are called "escape sequences" and are found in many different languages. They are used to encode non-printable characters such as newlines in letter strings (hardcoded).
Lua supports the following escape sequences:
-
\a
: Bell -
\b
: Backspace -
\f
: shape channel -
\n
: Newline -
\r
: Carriage return -
\t
: tab -
\v
: vertical tab -
\\
: backslash -
\"
: Double quote -
\'
: single quote -
\nnn
: Octal value (nnn
- 3 octal digits) -
\xNN
: Hexadecimal value (Lua5.2 / LuaJIT,NN
- two hexadecimal digits)
source to share