lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Very cool. :D  And that works in C too of course :)  Saves me some keystrokes

On Sun, Feb 14, 2010 at 2:38 AM, Jonathan Castello <solugon@hotmail.com> wrote:
> *laughs* In case you're curious, the original C++ comment abuse looked
> like this:
>
> /*/
>  std::cout << "One" << std::endl;
> /*/
>  std::cout << "Two" << std::endl;
> //*/
>
> You just change the first /*/ to /**/ to toggle, and the second /*/ to
> // to disable both. I actually believed I couldn't do this in Lua,
> until I read that multi-line comments also supported [=[ ]=] syntax!
>
> ~Jonathan Castello
>
> On Sun, Feb 14, 2010 at 2:30 AM, Majic <majic.one@gmail.com> wrote:
>> Nifty, do leik :D
>>
>> On Sun, Feb 14, 2010 at 12:01 AM, Jonathan Castello <solugon@hotmail.com> wrote:
>>> Let me try that again, from Gmail this time...
>>> ----
>>>
>>> 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
>>>
>>> On Sat, Feb 13, 2010 at 11:58 PM, Jonathan Castello <solugon@hotmail.com> wrote:
>>>>
>>>> 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/
>>>>
>>>
>>
>>
>