[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Locals in global namespace
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Mon, 11 Sep 2000 13:24:48 -0300 (EST)
>> Yes you can define a global variable inside a function. Variables without
>> 'local' are automatic global :-)
>Of course... I'm afraid you missed my point entirely. What I refer to is
>using local declarations in the global namespace, i.e. a program
>only consisting of "local x" (no functions, no nothing).
Then, I think you mean "top level in chunk", instead of "global namespace".
And yes, you can do that. In fact, having only local variables in a chunk
is a polite way of writing chunks -- loading such chunks does not overwrite
globals from others chunks by accident.
A more sophisticated use is to declare local variables in a chunk and use them
as upvalues in the functions that the chunk defines. This is a form of "static"
variables for chunks. Of course, the only real use is to define these locals
as tables, so that you can modify them later.