Locals Vs Globals |
|
|
* Program Analysis: The above point implies uses of local variables can often be more easily traced to their definition and vice-versa. This implies that locals can be easier to use for static program analysis, such as correctness checking/DetectingUndefinedVariables/LuaInspect and optimization (e.g. SourceOptimizer and LuaImplementations). |
|
* Program Analysis: The above point implies uses of local variables can often be more easily traced to their definition and vice-versa. This implies that locals can be easier to use for static program analysis, such as correctness checking/DetectingUndefinedVariables/LuaInspect and optimization (e.g. SourceOptimizer and LuaImplementations). Locals also reduce unintended coupling. |
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.