From what I remember learning port's version is recursive.... nuke's isn't (not that that's bad, saves on stack space)
well we were solving completely different problems. recursion is what makes fractals so damn awesome, want more detail, just run the output back through it some more.
i kinda use recursion in a couple places in lua to covert arrays (or tables as lua calls them) into function arguments. since you can also stick a reference to the function into a table, i stick the function as a named key and the arguments in order from 1-n (n=number of arguments). so i use a recursive function to convert those arguments into a list of arguments and then call the function, all with a single generic call. this is useful for setting up a call to a function that draws a hud gauge, but in a hook that doesnt have readily access to the screen. instead i setup the table as a global variable that gets passed to hud hook, and then when appropriate i deconstruct it into the function call and arguments, and it gets drawn at the correct time. its a lot neater than making almost every value a global.
function toargs(tab)
local len = #tab
if len >= 1 then
return tab[1], nextarg(tab,1,len)
end
end
function nextarg(tab,cur,len)
cur = cur + 1
if cur <= len then
return tab[cur], nextarg(tab,cur,len)
end
end
so if i have a function called drawLine(x,y,x2,y2) and i want to draw it sometime later with data thats only available right now. id do something like this
t = {}
t.func = drawLine
t[1] = 10
t[2] = 12
t[3] = 11
t[4] = 9
i can call that function with those args with this.
t.func(toargs(t))
since the # operator only counts consecutive neumeric indexes starting at 1, it will only count the numeric values. works pretty well.