[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to evade using globals in an if block
- From: Dirk Laurie <dirk.laurie@...>
- Date: Mon, 25 Aug 2014 09:26:56 +0200
2014-08-25 7:00 GMT+02:00 Paul Merrell <marbux@gmail.com>:
> In strict.lua,[1] its description states:
>
> -- checks uses of undeclared global variables
> -- All global variables must be 'declared' through a regular assignment
> -- (even assigning nil will do) in a main chunk before being used
> -- anywhere or assigned to inside a function.
>
> Is that language accidentally carried over from an earlier version of
> strict.lua for a Lua version that had different behavior in the global
> environment?
strict.lua is a debugging aid. A common source of error is simply
mistyping a name. Most of the time that will cause Lua to assume
that it is a global name, and its value when you use it will be nil.
In many cases, that will not yet cause an error. E.g
tbl = {a=one, b=two, c=there}
when you have carefully defined 'one', 'two' and 'three'.
Many lines down, the fact that tbl.c is nil causes a problem.
If you require 'strict.lua', the error is signalled right up there
where it happens.