• Announcement: Lua.org now officially recommends this forum as a meeting place for the Lua community

Question about comments (1 Viewer)

Herly Quijano

Newcomer
Joined
Mar 19, 2021
Messages
11
Reaction score
1
In others program languages you can do something like this:
C++:
/*Hello
How are you?*/
In Lua I think is
Lua:
--[[Hello
How are you?]]
Is there a way to do "comment" section but that looks like normal code to make it easier to look?
 
Last edited:

stetre

Member
Rank: I
Joined
Jan 8, 2020
Messages
48
Reaction score
34
Location
Italy
Website
github.com
Comments in Lua:

Lua:
-- this is a single line comment

--[[ 
this is a
multiple line
comment
--]]

print(" everything between --[[ and --]] is a comment")

--[=[
this is also
multiple line
comment
--]=]

print(" everything between --[=[ and --]=] is a comment")

--[==[
and also this is
a multiple line
comment
--]==]

print(" everything between --[==[ and --]==] is a comment")

--[===[
.. and so on, with as many '=' signs you like, provided you use the same number
of them in both the opening and closing delimiters.
(The delimiters with the '=' signs allow you to comment out sections that already
contain comments.)
--]===]
 

Herly Quijano

Newcomer
Joined
Mar 19, 2021
Messages
11
Reaction score
1
Comments in Lua:

Lua:
-- this is a single line comment

--[[
this is a
multiple line
comment
--]]

print(" everything between --[[ and --]] is a comment")

--[=[
this is also
multiple line
comment
--]=]

print(" everything between --[=[ and --]=] is a comment")

--[==[
and also this is
a multiple line
comment
--]==]

print(" everything between --[==[ and --]==] is a comment")

--[===[
.. and so on, with as many '=' signs you like, provided you use the same number
of them in both the opening and closing delimiters.
(The delimiters with the '=' signs allow you to comment out sections that already
contain comments.)
--]===]
Ok I see, but there is an answer to this?
Is there a way to do "comment" section but that looks like normal code to make it easier to look?
 

stetre

Member
Rank: I
Joined
Jan 8, 2020
Messages
48
Reaction score
34
Location
Italy
Website
github.com
Ok I see, but there is an answer to this?

If by "looks like normal code" you mean that it is subject to syntax highlighting like normal code, this is a concern for editors and IDEs, not for the programming language(s).

In Lua, however, you can easily uncomment a comment section (so that it becomes normal code) by just adding a single '-' character at the beginning of the opening delimiter:

Lua:
---[[
print("hello, world! ciao mondo!")
--]]

Then to comment it out again, just remove the extra '-':

Lua:
--[[
print("hello, world! ciao mondo!")
--]]
 

Herly Quijano

Newcomer
Joined
Mar 19, 2021
Messages
11
Reaction score
1
If by "looks like normal code" you mean that it is subject to syntax highlighting like normal code, this is a concern for editors and IDEs, not for the programming language(s).

In Lua, however, you can easily uncomment a comment section (so that it becomes normal code) by just adding a single '-' character at the beginning of the opening delimiter:

Lua:
---[[
print("hello, world! ciao mondo!")
--]]

Then to comment it out again, just remove the extra '-':

Lua:
--[[
print("hello, world! ciao mondo!")
--]]
I see.
 
Top