lua-users home
lua-l archive

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

On Thu, Feb 25, 2010 at 12:21 PM, David Given <> wrote:
> On 2010-02-25 00:53, Nevin Flanagan wrote:
> [...]
>> Does this mean that you can supply any value to _ENV, as long as it
>> provides __index and __newindex metamethods as required?
> Hmm. If I'm *not* using globals, can I assign nil to _ENV to get runtime
> errors if I tyop the name of a local?
> local string_len = string.len
> _ENV = nil
> a = 5 -- oops, forgot to local this
> Is there any chance of a facility to produce *compile* time errors if my
> code tries to reference globals? It would have to be possible to turn it on
> halfway through a chunk, once I'd finished loading locals from the global
> table (as in the example above).

I agree that it'd be a good idea, but I don't think that it would be
practical for Lua to use the detection of _ENV being set to nil for
it. For one thing, it's possible (though not popular) for nil to have
__index and __newindex metamethods, so it's an unsafe assumption that
reading/writing to nil is always an error.

So I think if we did have this it would need to be a new kind of
block. Something like:

  local do
    -- global sets/gets here are compile time errors

...all right, so "local do" doesn't really make much sense, but you
get the idea.