Locals Vs Globals |
|
foo
, _G.foo
, or getfenv().foo
(or in 5.2.0work3, _ENV.foo
). This allows different styles of environment usage, such as in ModuleDefinition.
local
statement, to use them. Assignments are global-by-default not LocalByDefault. Globals can be accessed on-the-fly, even with variable name set at runtime (e.g. "foo=io.stdin:read'*l'; return _G[foo]
"). The list of locals is defined statically. The list of globals may be determined at run-time and can even change during program execution.
local _G, math, math_sqrt = ...
", but this can be exhaustive.
local x = 1; do local _ENV = {x=2}; return x end
" returns 1.