Search code examples
luacommentsmultiline

Lua multiline comments past ]]'s


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?


Solution

  • 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
    --]=====]