lua-users home
lua-l archive

Re: Reset a Lua thread?

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Saturday 09, Patrick Donnelly wrote:
> On Sat, Apr 9, 2011 at 8:06 PM, Robert G. Jakabosky
> 
> <bobby@sharedrealm.com> wrote:
> > 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.
> 
> You can't use pcall like that in 5.1 if you want func to be able to yield.
Oops, I forgot about that.
-- 
Robert G. Jakabosky

AltStyle によって変換されたページ (->オリジナル) /