I would set up an enterFrame listener or coroutine, that breaks every x iterations. Then you could build a ‘stop’ button that cancels the processing and this method will give you a chance to click it before the processing resumes on the next frame.
[lua]
local currentIteration = 1
local iterationsPerFrame = 1000
local totalIterations = 1000000
local continueProcessing = true
local processLoop = function ()
if continueProcessing then
for i = currentIteration, currentIteration + iteractionsPerFrame, 1 do
– do your stuff using i as index if accessing a large table or something
currentIteration = currentIteration + 1
if currentIteration > totalIterations then
continueProcessing = false
break
end
end
end
end
Runtime:addEventListener(“enterFrame”, processLoop)
[/lua]