lua-users home
lua-l archive

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

Have you tried the Lua 5.1 '-w' cmdline flag? It catches all read/write to uninitialized globals, effectively safeguarding you from using them.

The only downside I have with it, is that a global being used (set up by 'rawset') may never, ever, be given 'nil' as a value. Or you're back in square one. Having a 'global' keyword to declare these would of course solve the issue.

(warning: look mailing list archives, there's a _lot_ discussion about this, that needen't be repeated?)


8.2.2005 kello 12:14, PA kirjoitti:


Now that I'm getting up to speed with Lua, I find the default behavior of assigning everything to the global environment quite disconcerting. It seems to me to be a case of "think locally, act globally". I would much more prefer the reverse: "think globally, act locally".

I'm aware of the setfenv() function, but this require a fair amount of hand holding, is too error prone for my taste as well as fairly obscure all things being equal.

What I would like to setup is something along the following lines:

- By default, things are always 'local' to the file (package) they are declared in. - If I want to export them to the 'global' name space I have to do so explicitly: "global MyGlobalStuff".
- Everything has to be either "local" or "global". No loose ends.

What would be a straightforward way to setup my Lua environment to achieve the above goals?

TIA :)


PA, Onnay Equitursay