I often run into one issue, that deferred functions forget the values of their own local variables.
The following code produces a nil-error, when the deferred function is run the second time:
Code:
function main(counter)
counter=counter+1
reaper.defer(main)
end
main(1)
So I would love to suggest, that the defer-function allows passing parameters as well, with which I can "memorise" the local variables.
If I don't pass a parameter, the deferred-function behaves as it already does right now, that the local parameter-variables are set as nil. So already existing scripts shouldn't break with that.
Code:
function main(counter)
counter=counter+1
reaper.defer(main, counter) -- like this way
end
main(1)
Otherwise I can use only global variables to keep their values, but this could be potentially dangerous in some situations. I love to keep variables local for the functions who are the only ones needing them.
Making them global means potential accidental overwriting of such a global variable an I'd love to avoid that.