lua-users home
lua-l archive

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


Thank you for the clarification, it makes many of the comments in this discussion more understandable. Now I will just have to go and fix my Luerl system which just creates one variable. :-)

Robert

----- Original Message -----
> From: "Dirk Laurie" <dirk.laurie@gmail.com>
> To: "Lua mailing list" <lua-l@lists.lua.org>
> Sent: Wednesday, 21 November, 2012 6:08:52 AM
> Subject: Re: Forward function declarations - relocal command
> 
> 2012/11/21 Robert Virding <robert.virding@erlang-solutions.com>:
> > Yes, of course local creates a new local. Your example was with a
> > nested do ... end block. What happens when they are in the same
> > block? This:
> >
> > local f=1 print(f)
> > local f print(f)
> >
> > prints
> >
> > 1
> > nil
> >
> > So does this
> >
> > local f
> > local f
> >
> > create two variables f?
> 
> Yes.
> 
> > Before the second I access the first (of course) but after the
> > second local I can only access the second one?
> 
> Yes. _During_ the second. if you had for example
>    local f = f..'a'
> or
>    local f = function(x) return f..x end
> or
>    local function f(x) return f..x end
> you would still be accessing the first.
> 
> > Or does the second one just set the value of f to nil?
> The second one does not even check whether there was
> a first.
> 
> The function debug.getlocal can see all local variables,
> even shadowed ones. See my post of 19 Nov in this thread.
> 
>