[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Reset a Lua thread?
- From: "Robert G. Jakabosky" <bobby@...>
- Date: Sat, 9 Apr 2011 17:06:49 -0700
On Saturday 09, Anthony Howe wrote:
> Is it possible somehow to reset a Lua coroutine thread in the event of a
> script error or some such, without having to nuke the thread and
> recreate the thread's state?
I think something like this would work. (Warning un-tested code).
function resettable_thread(func)
return coroutine.create(function()
repeat
coroutine.yield(pcall(func))
until false
end
end
It will always restart the thread with the same function. You could use a
more complex wrapper to allow changing the function that the thread runs.
--
Robert G. Jakabosky