lua-users home
lua-l archive

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


On Fri, Jul 16, 2010 at 1:35 AM, Miles Bader <miles@gnu.org> wrote:
> Jonathan Castello <twisolar@gmail.com> writes:
>>> The implementation suggested by Roberto looks quite useful, is optional,
>>> and would be off by default for backward compatibility.  So what's the
>>> problem, exactly?
>>
>> IMHO it's kind of ugly/clunky and feels like a band-aid to me, but I
>> mainly just use Lua embedded within a host application, so I could be
>> missing something. When I write small utility libraries, I pretty much
>> create my own "environment" table and return that from the chunk. My
>> feeling is that it would be simplest if this were the default, and
>> everything within a chunk was always executed within a new
>> environment. Then I wouldn't have to worry about accidentally
>> cluttering the calling code's space at all.
>
> I don't know that the problem is so much one of "cluttering the calling
> code's space", but more of "catching programming errors."
>
> That, AFAIK, is the main reason people don't like Lua's traditional
> behavior -- it lets mistakes in variable names slip by unnoticed.
>
> -Miles
>
> --
> Cannon, n. An instrument employed in the rectification of national boundaries.
>

I personally haven't had too many nightmares from misspelling variable
names, but under my suggestion you could likely list out the
environment's entries and see if anything's there that shouldn't be.
It would be easier than looking through a potentially cluttered shared
environment like we have by default now, and probably easier than
reading through the file to spot a problem.

If you want strict declaration of variables in the environment, it
shouldn't be hard to create a strict.lua-alike that requires
declarations with a global() function before they can be assigned to.

-- 
~Jonathan