lua-users home
lua-l archive

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


On Fri, Oct 28, 2011 at 20:02, Tom N Harris <telliamed@whoopdedo.org> wrote:
> On 10/28/2011 04:09 AM, HyperHacker wrote:
>>
>> This has bit me a few times, when writing functions to parse other
>> languages:
>> function funcs.foo(...) doThings() end --OK!
>> function funcs.for(...) doStuff() end --Invalid!
>> function funcs['for']() doStuff() end --Also invalid! (a function
>> can't be defined using this syntax)
>> The only way is to write:
>> funcs['for'] = function(...) doStuff() end --OK, but harder to read,
>> especially alongside those like the first line.
>>
>> Could these restrictions not be lifted? An expression such as [[
>> blah.for i = 1,5 ]] wouldn't be syntactically valid, so there doesn't
>> appear to be any ambiguity to worry about. Especially I don't
>> understand why line 3 isn't acceptable.
>>
>
> I patched the parser to read NAME as a 'namelit' which is parsed as:
>
>    namelit -> NAME | reserved word | '[' String ']'
>
> In my case, it was to allow illegal characters in a function name, such as
> ["Check?"].
>
> https://github.com/whoopdedo/lgscript/commit/4e3ac5b9ec5be3f3306db7f1d83bca3f36e81d8a
>
> This is just coddling coders who don't want to type _G["Check?"] =
> function(...) end. Well, you can also use it for locals, but then we're
> encouraging bad habits. So I would not want to see it become part of Lua. Or
> at least, don't accept reserved words.
>
> --
> - tom
> telliamed@whoopdedo.org
>
>

I did similar once to allow @ and $ in identifier names, with the
intention that they be used for special cases. I don't think I ever
submitted that patch anywhere, but it's fairly trivial to do...

-- 
Sent from my toaster.