[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: A little comment randomness
- From: Jonathan Castello <solugon@...>
- Date: Sat, 13 Feb 2010 23:58:34 -0800
Back when I used to use C++ a lot, I came up with a creative abuse of comments to let me decide which of two sections to compile based on the presence of a single character. I just happened to come up with a similar construct in Lua as well, and I thought I'd share it. I don't know if anyone else has come up with it before - it /is/ really simple - but it occurred to me as I read the section on comments in the "The Evolution of Lua" PDF.
--[[ print("one")--[=[ <Two-way comment> ]] print("two")--]=]
This construct will only allow print("two") to be executed. By adding a - to the first comment, the structure 'toggles', and only print("one") executes. It also just so happens that you can disable both blocks at once by changing [[ to [=[. Lastly, no matter how it's toggled, the middle comment has a convenient space for a human-readable comment.
I'm not sure how useful this would be to anyone else, but I like to use constructs like this to preserve old code while I'm developing a newer block.
~Jonathan Castello
_________________________________________________________________
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free.
http://clk.atdmt.com/GBL/go/201469229/direct/01/