-- \t 制表符,\n 换行,\r 回车,
-- \" 或 \' 引号,\\ 反斜杠
local escaped = "She said \"Hello!\" to me."
-- escaped = She said "Hello!" to me.
-- 换用另一种引号:无需转义
local other_quotes = 'She said "Hello!" to me.'
-- other_quotes = She said "Hello!" to me.
local apostrophe = "It's fine"
-- apostrophe = It's fine
-- 按编码:\x 十六进制、\u{} Unicode、\ddd 十进制
local letters = {"\x41", "\u{41}", "\065"}
-- letters = A, A, A
-- 在 [[ ]] 中,反斜杠保持原样
local path = [[C:\Temp\new]]
-- path = C:\Temp\new
-- %q 给出带引号的文本,Lua 可以把它读回来
local quoted = string.format("%q", escaped)
-- quoted = "She said \"Hello!\" to me."
-- 未知的转义序列会在编译期报错
local chunk, err = load([[return "\d"]])
-- chunk = nil
-- err = [string "return "\d""]:1: invalid
-- escape sequence near '"\d'
print("escaped = " .. escaped)
print("other_quotes = " .. other_quotes)
print("apostrophe = " .. apostrophe)
print("letters = " .. table.concat(letters, ", "))
print("path = " .. path)
print("quoted = " .. quoted)
print("chunk = " .. tostring(chunk))
print("err = " .. err)