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: Ignacio Burgueño <ignaciob@...>
- Date: 2009年5月21日 15:47:07 -0300
Roberto Ierusalimschy wrote:
Lua 4 does not have lexical scope, so you should use upvalues. But you
cannot use an upvalue before giving it its final value. One way out
of this is to use a table to create an indirection:
function F ()
local t = {}
t.G = function (value)
if value == 10 then
return "stop"
end
return %t.G(value + 1)
end
print( t.G(1) )
end
Not pretty, but I cannot think of anything better.
Thanks Roberto. I didn't occur to me to use a table. It is prettier than
passing the function around.
Regards,
Ignacio Burgueño