lua-users home
lua-l archive

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


On Wed, 24 Apr 2013 23:18:19 +0200
Dirk Laurie <dirk.laurie@gmail.com> wrote:

> > Because Lua supports proper lexical scoping and nested closures so
> > thoroughly (as opposed to, e.g., Python), default local would be
> > untenable. The most sensible and simplest rule is what Lua uses,
> > IMO.
> 
> I use a simple metatable modification to catch assignments to global
> variables whose names match a certain pattern, currently "^%a%d?$".
> I.e. names like `i` or `a1` will trigger a warning. Not foolproof of
> course, but I try to follow the rule that anything I genuinely want
> in `global` must have a nume that does not math that format.


Dirk, this is outstanding news. I'd like my interpreter to croak on any
global that doesn't begin with "glv". Given that I almost never
use any globals on purpose (except for procedures), your mod will catch
all my omissions of the word "local". Having to mark all my functions
local would be a small price to pay for *knowing* I haven't
accidentally used globals.

Could you please post a link to your modification so I can use it?

Thanks,

SteveT

Steve Litt                *  http://www.troubleshooters.com/
Troubleshooting Training  *  Human Performance