lua-users home
lua-l archive

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

I forgot to mention, the tool for restricting redefinition should not be 
used in earnest. If you do, you will find that various things don't work, 
like for loops over tables. It can be used within a code module, but you 
need to change the setfenv(0) stuff to setfenv(1); then it doesn't protect 
things typed directly in the Lua standalone interpreter.

The reason for this is that various parts of the Lua core assume that 
certain things are in the global environment and are accessible with 
rawget. One example, actually shown in the example code, is _TRACEBACK; 
others include next and ipairs and there might be a few others I've 

This is a bit of a crock, really. You can add these things as redefinable 
names, but that makes them redefinable (and things can get wierd if you 
redefine next, for example). 

Here is the symptom: (continuing from the previous printout)

> for k, v in _G do print(k) end
stdin:1: attempt to call a nil value
stack traceback:
        stdin:1: in main chunk
        [C]: ?
> = next
> for k, v in _G do print(k) end

One solution would be to create a Lua standalone that maintains a separate 
environment for the read-eval-print loop, and reserves the global 
environment for stuff that needs to be in the global environment. None of 
this is perfect.... I think there is room for more thought about 
environments in general.