lua-users home
lua-l archive

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


I don't think you can do that anymore. In the old days you could use %x
to give you the "upvalue" of x, which was the outer scope value. I
believe upvalue syntax has been removed, which is probably a good thing.
You can't get the outer scope value in C/C++ when you have a clash, and
neither can you in Lua. Unless you use the debug interface (don't!) I
don't think you can get the value without nasty coding. Refactor your
algorithm or copy the value.

Regards,
Nick


> -----Original Message-----
> From: Leandro Candido [mailto:enclle@click21.com.br]
> Sent: Wednesday, October 15, 2003 3:03 PM
> To: Lua list
> Subject: Re: local and global
> 
> Hello,
> 
>     No, what I want is to access x in [level-1], this is the x global
to
> the
> block/scope. Example:
>     --x = 123 -- _G.x
>     function test()
>             local x = 123 --< I want to access this
>             for i = 0,10 do
>                 local x = x + i --< [local x] = 246 + i
>                 if x == 130 then
>                     [global x ] = x --< [x this level-1] = [local x]
>                 end
>     end
> 
>                         Thanx,
> 
>
Leandro.
> 
> ----- Original Message -----
> From: "Daniel Silverstone" <dsilvers@digital-scurf.org>
> To: "Lua list" <lua@bazar2.conectiva.com.br>
> Sent: Wednesday, October 15, 2003 6:59 AM
> Subject: Re: local and global
> 
> 
> > On Wed, 2003-10-15 at 04:22, Leandro Candido wrote:
> > >     How can I access a global variable after a redeclaration as a
> local?
> Ex:
> > >             [global x] = -x -- global x = negative of local x
> >
> > If you *definitely* mean global rather than "local in enclosing
scope"
> > then...
> >
> > _G["x"] or just _G.x should do what you want (unless I'm horribly
> > mistaken)
> >
> > D.
> >
> > --
> > Daniel Silverstone
http://www.digital-scurf.org/
> > Hostmaster, Webmaster, and Chief Code Wibbler: Digital-Scurf
Unlimited
> > GPG Public key available from keyring.debian.org       KeyId:
20687895
> >
> >
>