lua-users home
lua-l archive

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

Biggest feature request on my radar is to sort out the automatic global variables issue which seems to me to be the only serious design flaw in Lua (and yes, I can see how it probably developed historically as Lua got progressively used for larger projects than originally intended). I know Roberto has code to work round this, but when I tried it it crashed Girder spectacularly! It is also expensive looking.

What I'm looking for is something like OPTION EXPLICIT available in some versions of Basic. This disables automatic global variables and forces you to declare them before use. In Lua, there'd be a switch you'd put at the start of each chunk and it would force you to use = value syntax to CREATE an entry in the global environment table (or in Lua cant, to set an entry to a value other than nil). You would still be able to access or reassign an existing global without the _G syntax.

I suggest that, under OPTION EXPLICIT you would also have to use _G to set a variable to nil to make it harder to accidentally delete someone else's global.

It would be good to also be able to set OPTION EXPLICIT as the default when creating a Lua interpreter in C.

I'm only using OPTION EXPLICIT as shorthand here as it is something people might be familiar with. In many ways, I'd prefer OPTION LOCAL and OPTION GLOBAL (or some other syntax for flagging directives). Here OPTION GLOBAL is what we've got now. OPTION LOCAL would behave as suggested above, but additionally it would allow dropping of explicit "local" specification of variables. Variables without a table specifier would be created local.

Would Roberto maybe admit that if he was redesigning Lua from scratch today variables would be local by default and global by declaration? If not, why not?

- John