lua-users home
lua-l archive

Re: [ANN] Microlight (was Re: paving cowpaths with libraries)

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


It was thus said that the Great steve donovan once stated:
> On Fri, Feb 17, 2012 at 2:25 AM, ernie <elukie@comcast.net> wrote:
> > What is the reason for this on line 148?
> >
> >    local tbuff  -- <=======
> >    function tbuff (t,buff,k)
> >        ...
> >    end
> 
> tbuff is a recursive local function, so the symbol must be declared
> before the definition. It helps to remember that 'local function f' is
> short for 'local f = function' - so any reference to f in that
> _anonymous_ function doesn't find the local because it's not defined
> yet.
> 
> local tbuff
> tbuff = function (t,buff,k)
> .-- refer to local tbuff!
> ...
> end
 But then how does this work?
local function foo(x)
 if x == 0 then
 print("done")
 else
 print(x)
 return foo(x-1)
 end
end
foo(3)
 -spc (And it does)

AltStyle によって変換されたページ (->オリジナル) /