Lua错误:nesting of [[...]] is deprecated near '['

第一天学习Lua,正在按照《Lua程序设计(中文版)》学习。运行2.4节“使用[[...]]表示字符串”出现“nesting of [[...]] is deprecated near '['”的错误,错误截图如下。那么要如何解决呢?

lua_nest_error

查阅Programming in Lua(3rd ed)P32,可以找到答案。

Sometimes, you may want to enclose a piece of code containing somethinglike a=b[c[i]] (notice the ]] in this code), or you may need to enclose some codethat already has some code commented out. To handle such cases, you can addany number of equal signs between the two open brackets, as in [===[. Afterthis change, the literal string ends only at the next closing brackets with thesame number of equal signs in between (]===], in our example). The scannerignores pairs of brackets with a different number of equal signs. By choosing anappropriate number of signs, you can enclose any literal string without havingto add escapes into it.

由上所述,当使用“[[…]]]”的方式标记字符串时,如果这段字符串中出现了“]]”,为防止错误,可以改用“[==[…]==]”来包围字符串。其中,等号的数量没有特殊要求,只要前后双中括号中所夹等号的数量保持一致,就被视为是对应的一对。比如用“[=[”和“]=]”以及“[===[”和“]===]”包围字符串,都是可行的。同理,当我们用“--[[…--]]”进行多行注释时,也可以通过添加等号的方式规避类似错误。

lua_nest_modified

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值