lua-users home
lua-l archive

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


On Sat, Dec 14, 2002 at 09:47:35AM -0200, Luiz Henrique de Figueiredo wrote:
> >function __read_value(__name)
> >  local __ret, __gotit = %__get_local(__name);
> >  if( __gotit == nil ) then
> >    return %rawget(%globals(), __name);
> >  end
> >  return __ret;
> >end
>  return %__get_local(__name) or %rawget(%globals(), __name)

What about if you have a local variable with the value 'nil' -- this
will not mask a global of the same name, which thus provides different
semantics to the normal 'local' concept.

E.g...

> a=5
> function boo() local a = nil; print(a); end
> boo()
nil
> 

The important bit, is that I have to return two values from
__get_local() so that I can tell if the 'nil' I get back is because
there was no local of that name, or because there was a local of that
name whose value was nil.

If there was a way of doing

 return %__get_local(__name) (or if result2==nil, %rawget(%globals(), __name))

Then that's what we need.

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
Your lucky color has faded.