Comments in LUA
November 15th, 2007 Posted in Lua, Tips'n'Tricks, UKAs you know, you can put comments in LUA with the double hyphen (–):
-- This is a comment DoSomething(); -- This is another comment. ReDoSomething();
But the double hyphen is not very convenient for commenting multiple lines. Like in C language, there is a multi-lines comment:
--[[ This is a ... multiline... comment! --]] DoSomething();
This multiline or block comment is really cool since you can enable or disable a piece of code using a single hyphen.
Hereafter, the function mySqr_v1 is commented:
--[[ function mySqr_v1(a) return a * a; end --]] function mySqr_v2(a) local b = a*a; return b; end
and now, you can simply uncomment it with one hyphen:
---[[ function mySqr_v1(a) return a * a; end --]] function mySqr_v2(a) local b = a*a; return b; end
Now both functions are active!
Wath-out: –[[ .... --]] is the right manner. I often see –[[ .... ]]– which seems to work but it’s wrong.
You must be logged in to post a comment.