Re: Recursive functions in Lua 4
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Recursive functions in Lua 4
- From: Rob Kendrick <lua-l@...>
- Date: 2009年5月21日 17:17:06 +0100
On 2009年5月21日 13:00:56 -0300
Ignacio Burgueño <ignaciob@inconcertcc.com> wrote:
> Hi. I have to maintain some Lua 4 code, and I have no idea how to
> make a local function call itself.
> In the following code, I'd like to make G local to the function F. Is
> this possible?
>
> function F()
>
> G = function(value)
> if value == 10 then
> return "stop"
> end
> return G(value + 1)
> end
>
> print( G(1) )
> end
Yes. Declare the local variable before assigning to it;
function F()
local G
G = function(value)
if value == 10 then
return "stop"
end
return G(value + 1)
end
print( G(1))
end
B.