Hello!
2013/7/24 Linglin:
> 应该就是,请问这个问题如何处理呢?我知道PYTHON里面有“”“ """可以忽略里面的引号
>
Lua 语言里有一个类似的 long brackets 记法。
引用一下 Lua 5.1 官方手册中的相关文档:“Literal strings can also be defined using a
long format enclosed by long brackets. We define an opening long
bracket of level n as an opening square bracket followed by n equal
signs followed by another opening square bracket. So, an opening long
bracket of level 0 is written as [[, an opening long bracket of level
1 is written as [=[, and so on. A closing long bracket is defined
similarly; for instance, a closing long bracket of level 4 is written
as]====]. A long string starts with an opening long bracket of any
level and ends at the first closing long bracket of the same level.
Literals in this bracketed form can run for several lines, do not
interpret any escape sequences, and ignore long brackets of any other
level. They can contain anything except a closing bracket of the
proper level.”
比如
local html = [==[
<pre id="blah">Tom says, "Bob says, 'Hi!'".</pre>
]==]
更多细节和示例可以参见 Lua 5.1 官方手册:http://www.lua.org/manual/5.1/manual.html#2.1
另外,值得一提的是,如果你是把 Lua 代码作为 nginx 配置文件字符号放在 nginx.conf 中的话,还要小心 Nginx
字符串本身的转义问题。所以一般,建议把较复杂的 Lua 代码放在外部独立的 .lua 文件中,然后在 nginx.conf 中直接通过
content_by_lua 和 rewrite_by_lua 这样的配置指令直接引用一下 .lua 文件的路径就可以了。
Best regards,
-agentzh