Lua multiline comments past ]]'s

Jonathan Picazo picture Jonathan Picazo · Mar 28, 2014 · Viewed 33.5k times · Source

I'm trying to find out a way to use a multiline comment on a batch of code, but it keeps mistaking some syntax in it as a ]] and thinking I want it to end there, which I don't!

--[[
  for k,v in pairs(t) do
    local d = fullToShort[k]
    local col = xColours[v[1]] -- It stops here!
    cecho(string.format(("<%s>%s ", col, d))
  end
--]]

I thought I read somewhere it was possible to do use a different sort of combination to avoid those errors, like --[=[ or whatnot... Could someone help?

Answer

Seagull picture Seagull · Mar 28, 2014

As you can see in Strings tutorial there is a special [===[ syntax for nesting square braces. You can use it in block comments too. Just note, that number of = signs must be the same in open and close sequence.

For example 5 equals will work.

--[=====[ 
  for k,v in pairs(t) do
    local d = fullToShort[k]
    local col = xColours[v[1]] -- It stops here!
    cecho(string.format(("<%s>%s ", col, d))
  end
--]=====]