[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: disabling global definitions within function blocks
- From: "xenarcher <nickl@...>" <nickl@...>
- Date: Tue, 07 Jan 2003 21:54:46 -0000
--- 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?