Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Literal Strings [Lua 5.1]

So I started to learn Lua(5.1) and I saw that thing called literal strings. And I have no idea what these do. The manual says \a is a bell but when I type

print('hello\athere')

The IDE prints a weird square with 'bel' written on it. So if someone could help me and explain every one of them[Literal Strings]. that would be really helpful.

p.s. i use Sublime Text 3

like image 505
Sosolol Avatar asked Aug 31 '25 10:08

Sosolol


2 Answers

Only ASCII between 0x20 and 0x7E are printable characters. How other characters are output, including '\a' and '\b', is up to the implementation.

'\a', the ASCII 7 for BEL, is designed to be used to alert. Typical terminal would make an audible or visible alert when outputing '\a'. Your IDE choose to show a different output other than an alert. That's OK since it's up to the implementation.

like image 52
Yu Hao Avatar answered Sep 03 '25 01:09

Yu Hao


Such sequences are called "escape sequences", and are found in many different languages. They are used to encode non-printable characters such as newlines in literal (hardcoded) strings.

Lua supports the following escape sequences:

  • \a: Bell
  • \b: Backspace
  • \f: Form feed
  • \n: Newline
  • \r: Carriage return
  • \t: Tab
  • \v: Vertical tab
  • \\: Backslash
  • \": Double quote
  • \': Single quote
  • \nnn: Octal value (nnn is 3 octal digits)
  • \xNN: Hex value (Lua5.2/LuaJIT, NN is two hex digits)
like image 22
Colonel Thirty Two Avatar answered Sep 03 '25 00:09

Colonel Thirty Two