Lua 转义多行字符串

Lua escape multiline string

你好,我想知道我是否可以在多行字符串中转义 [[ 和 ]]

示例:

s = [[  [[ test ]] ]]

然后如果我这样做

print(test)

我希望输出为 [[ test ]]

有没有办法做到这一点?

s = [=[ [[Hello]] ]=]
print(s)

输出 [[Hello]]

似乎可行,但我只是在研究回答这个问题时学习这个解决方案,所以我不知道是否有任何注意事项。

Lua 多行字符串不只是使用 [[]];你也可以在 [] 之间放置尽可能多的 = (但必须是相同的数字):

local str = [=====[
 ]] This does nothing
 ]=] not enough =
 ]==========] too many =
]=====] -- This closes the string