Sounds like you'd be better off defining groups of functions, rather then trying to split one all-inclusive list at set points with a "return" code. Either way, if you pass control back to the parent script, then suddenly you've lost your server-crash protection… is that right, or am I still off-base?
Anyway, in regards to your "addTask" system, why not pass the functions as the names of their table keys, along with any arguments they need? Not sure how you're going to record them otherwise (it's not like you can store the pointer!). For eg, say you do:
progress.addTask( {"turtle","select"}, {1} )
In the API, you'd then do something like:
function addTask(functionTable, argsTable)
table.insert(taskTable,{["functionTable"]=functionTable,["argsTable"]=argsTable})
end
function runTask(task)
local myFunction = _G
for i=1,#taskTable[task].functionTable do myFunction = myFunction[taskTable[task].functionTable[i]] end
myFunction(unpack(taskTable[task].argsTable))
end
function startTasks()
for i=1,#taskTable do runTask(i) end
end
… plus whatever "saving" or other organisational work you want to perform. I suspect this'd also make it easier for you to implement your "returning" thing, whatever the problem with that is.
By the by, I quite liked
this solution to the resuming thing, in case you've not seen it. It's not exactly finished (nor would it even be
practical to deal with all possible scenarios - the results of file reads for eg), but the basic idea behind it is a very simple one which struck me as very clever.