Escape characters

Basic types / Character type

-- \a alert, \b backspace, \f form feed,
-- \n new line, \r carriage return, \t tab,
-- \v vertical tab, \\ backslash, \" and \' quotes
local escapes = {"\a", "\b", "\f", "\n", "\r",
                 "\t", "\v", "\\", "\"", "\'"}

-- Each one is a single char: show its code
local codes = {}
for index, char in ipairs(escapes) do
  codes[index] = char:byte()
end
-- codes = 7, 8, 12, 10, 13, 9, 11, 92, 34, 39

-- \xHH: two hex digits
local hex = "\x41"
-- hex = A

-- \ddd: up to three DECIMAL digits
local decimal = "\101"
-- decimal = e

-- Strings may contain \0, a null char
local zero_length = #"\0"
-- zero_length = 1

-- No \e: the escape char is \x1b
local escape_code = string.byte("\x1b")
-- escape_code = 27

print("codes = " .. table.concat(codes, ", "))
print("hex = " .. hex)
print("decimal = " .. decimal)
print("zero_length = " .. zero_length)
print("escape_code = " .. escape_code)