lua-users home
lua-l archive

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


--- In lua-l@yahoogroups.com, Luiz Henrique de Figueiredo <lhf@t...> 
wrote:
> For a Lua 5.0 solution see test/readonly.lua in the alpha or beta 
distributions.

This seems to work nicely, but only at the level at which setglobals
() is called. For instance, say you have the following:



-- this code is extracted from test/readonly.lua
local f=function (t,i) error("cannot redefine global variable 
`"..i.."'",2) end
local g={}
local G=getglobals()
setmetatable(g,{__index=G,__newindex=f})
setglobals(1,g)

-- test function
function foo() x = 1 end

foo()  -- no error
y = 1  -- error


When foo() is called, no error occurs. Is there a way to propagate 
"read-only globals" to all function calls (at any level 
of nesting) following the setglobals() call?