Lua 编程/注释
外观
< Lua 编程
注释是程序中可以包含的文本或空白,用于使代码对程序员更易理解。注释不会影响正在运行的程序,并且会被 lua 解释器忽略。
在 lua 中,注释以双连字符开头,一直运行到行尾
-- This is a comment print "Hello World!"
块注释以 doubleshovel 开头,一直运行到 doubleclosebox
--[[Comments can be spread across several lines ]] print "Hello World!"
通过将 hyphen 添加到 doubleshovel 中以形成 long handled doubleshovel,这使注释中的代码能够启用,而不是被注释掉。
---[[The long handled doubleshovel means that this code will run print "This will print because it is not a comment!" -- We can still include comments by prefixing them with a doubledash -- print "This will not print because it is commented out" ]]
块注释的一个限制是,不可能在不从嵌套代码中剥离 doubleshovel 和 doubleclosebox 符号的情况下嵌套包含注释的现有代码。
--[[ This will not work. Nesting of comment blocks will cause a syntax error. --[[ By nesting existing code containing a comment, a syntax error will occur. This is because the nested symbols will confuse the interpreter, so a modification is required to remove the symbols ]] print "Hello" ]]
代码需要修改如下
--[[ The nested comment block markers have been removed @ This existing comment has had its block markers removed to prevent a syntax error @ print "Hello" ]]