lua-users home
lua-l archive

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


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