Lua Getting started with Lua Comments


Example

Single-line comments in Lua start with -- and continue until the end of line:

-- this is single line comment
-- need another line
-- huh?

Block comments start with --[[ and end with ]]:

--[[
    This is block comment.
    So, it can go on...
    and on...
    and on....
]]

Block comments use the same style of delimiters as long strings; any number of equal signs can be added between the brackets to delimit a comment:

--[=[
    This is also a block comment
    We can include "]]" inside this comment
--]=]

--[==[
    This is also a block comment
    We can include "]=]" inside this comment
--]==]

A neat trick to comment out chunks of code is to surround it with --[[ and --]]:

--[[
    print'Lua is lovely'
--]]

To reactivate the chunk, simply append a - to the comment opening sequence:

---[[
    print'Lua is lovely'
--]]

This way, the sequence -- in the first line starts a single-line comment, just like the last line, and the print statement is not commented out.

Taking this a step further, two blocks of code can be setup in such a way that if the first block is commented out the second won't be, and visa versa:

---[[
  print 'Lua is love'
--[=[]]
  print 'Lua is life'
--]=]

To active the second chunk while disabling the first chunk, delete the leading - on the first line:

--[[
  print 'Lua is love'
--[=[]]
  print 'Lua is life'
--]=]