lua-users home
lua-l archive

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


On Sun, Aug 24, 2014 at 12:01 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:

> -- declares globals needed in function
> strMessage = nil
> bTerminate = nil
>
> That comment is wrong. Those two statements in fact _remove_
> the corresponding global variables if they existed, since in Lua 5.2
> they are equivalent to
>
> _ENV.strMessage = nil
> _ENV.bTerminate = nil
>
> which removes the keys concerned from the table _ENV.

After some headscratching, I remembered where I got the notion to do
that. 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? Or perhaps something else was intended than my
understanding of that guidance? Assigning nil to a global in a main
chunk does stop strict.lua from griping about globals being assigned
within a function. Maybe the description was intended as a method to
disable the strict.lua griping rather than as a method to make an
assignment? If so, I think a somewhat more enlightening description
would be helpful to novices.

Best regards,

Paul

[1] <http://www.lua.org/extras/5.2/strict.lua>.



-- 
[Notice not included in the above original message:  The U.S. National
Security Agency neither confirms nor denies that it intercepted this
message.]