Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 617
Jonathan Picazo Avatar asked Mar 28 '14 20:03

Jonathan Picazo


People also ask

How do I multiline a comment in Lua?

A comment starts with a double hyphen ( -- ) anywhere outside a string. They run until the end of the line. You can comment out a full block of code by surrounding it with --[[ and --]] . To uncomment the same block, simply add another hyphen to the first enclosure, as in ---[[ .

Which is the correct way to put multi multiline comment?

Using triple-quoted string literals Another way to add multiline comments is to use triple-quoted, multi-line strings. These strings are to be used carefully and should not be confused with Docstrings (triple-quoted string literals appearing right after a function/class/module to generate documentation).

Which instruction we can use multiple comment lines?

Multiline Comments You can comment multiple lines by the special beginning tag <! -- and ending tag --> placed before the first line and end of the last line as shown in the given example below.

Which characters are used for multiline commenting?

Hash character(#) is used to comment the line in the Python program. Comments does not have to be text to explain the code, it can also be used to prevent Python from executing code. The hash character should be placed before the line to be commented.


1 Answers

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 --]=====] 
like image 139
Seagull Avatar answered Sep 19 '22 11:09

Seagull