lua-users home
lua-l archive

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


On 28 October 2011 17:53, Stefan Reich
<stefan.reich.maker.of.eye@googlemail.com> wrote:
> On Fri, Oct 28, 2011 at 9:28 AM, Miles Bader <miles@gnu.org> wrote:
>> HyperHacker <hyperhacker@gmail.com> writes:
>>> funcs['for'] = function(...) doStuff() end --OK, but harder to read,
>>> especially alongside those like the first line.
>>
>> c'mon, that's not _that_ bad, especially given that it will only
>> rarely need to be used.  It's arguably even a good thing, since it
>> explicitly makes the point "hey this function name is a keyword, so be
>> careful..."
>
> Yeah, it sounds really smart to use "for" as a function name in your
> Lua code :-))
>
> (Hilarity ensues!)

Sometimes, you cannot avoid it. For example when generating a 1-1
binding to a library which uses methods named as Lua keywords. An
example of this is the Qt library - 19 of it's classes have a method
named 'end' [1], which you cannot call using Lua's syntax sugar. You
have to call it as follows:

    painter['end'](painter)

Does someone propose an elegant way to handle this? :)

[1] http://doc.qt.nokia.com/4.7/functions.html