[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Table dot number?
- From: HyperHacker <hyperhacker@...>
- Date: Fri, 28 Oct 2011 02:09:29 -0600
On Fri, Oct 21, 2011 at 10:07, Roberto Ierusalimschy
>> >> I understand, but what is the exact rule for what is allowed after the dot? Same
>> >> rules as names for variables?
>> > That's exactly it, 1 is not a valid identifier, so you cannot use the sugar that
>> > says that t.x == t["x"].
>> In addition, you cannot use Lua keywords after the dot, like 't.end'
>> or 't.for' - even though they *could* always be unambiguously
>> distinguished from proper keywords in this context.
> A detail: This is not "in addition"; it is exactly the same rule. "end"
> is not a valid identifier.
> -- Roberto
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.
Sent from my toaster.