lua-users home
lua-l archive

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


On 16/07/2010, at 4:04 AM, Roberto Ierusalimschy wrote:

>> "global checks" as a statement doesn't "turn on" global assignment
>> checking? Global assignment checking would be always on? Or is this
>> simply how it works at the file chunk level? (Perhaps a new thread
>> discussing the new change is warranted like the earlier "a new
>> proposal for environments" thread. It would be most helpful to have an
>> authoritative description of the proposed design.)
> 
> There is a good chance that this proposal will not go into 5.2; but
> anyway, just to make it clear:
> 
> - there is a new keyword "global" that can be used in the same places
> that "local" can be used (namely "global function ..." and
> "global a,b,c...").
> 
> - "global function foo ..." expands to "global foo; foo = function ..."
> (just like "local function" does).
> 
> - Names declared with "global" follow the same scoping rules of
> names declared with "local", in the same name space.
> 
> - Any use (access and assignment) of "a" in the scope of a "global a"
> declaration is translated to "_ENV.a".
> 
> - Any access to a free "a" (that is, outside any declaration for "a")
> is translated to "_ENV.a".
> 
> - Any assignment to a free "a" that is outside the scope of any
> other global declaration is translated to "_ENV.a".
> 
> - An assignment to a free "a" that is inside the scope of another global
> declaration is an error ("attempt to assign to undeclared variable
> 'a'").
> 
> 
> -- Roberto

Does this mean that if we wish to have global checking for variables in a module, we'll have to go "global function" for the rest of the module to get module functions?  From the first global on function mymodulefunction(...) will be an error right?

Geoff