[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: disabling global definitions within function blocks
- From: "Thatcher Ulrich" <tu@...>
- Date: Tue, 7 Jan 2003 20:14:15 -0500
On Jan 07, 2003 at 09:54 -0000, xenarcher <nickl@volition-inc.com> wrote:
> --- 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.
Are you sure? I'm seeing an error with the above code, as expected,
using lua-5.0-beta.
I actually get two errors; with the above code verbatim I get an error
on the definition of "foo". If I predefine a "foo" slot in g, then I
get the expected error on "x = 1".
--
Thatcher Ulrich
http://tulrich.com