[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Table dot number?
- From: HyperHacker <hyperhacker@...>
- Date: Fri, 28 Oct 2011 23:51:39 -0600
On Fri, Oct 28, 2011 at 20:02, Tom N Harris <firstname.lastname@example.org> wrote:
> On 10/28/2011 04:09 AM, HyperHacker wrote:
>> This has bit me a few times, when writing functions to parse other
>> 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
> 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
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.