[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: how to clear error info from a state?
- From: David Given <dg@...>
- Date: Wed, 10 Dec 2008 11:13:53 +0000
> if i call luaL_error, the coroutine will stop and then the outer
> lua_resume will return the error string which pass from luaL_error.
> my questing is: how to reuse the lua_state?
> i've tried to clear the stack,push a new chunk and then call
> lua_resume,but it said:"cannot resume non-suspended coroutine".
Unless there's some cunning way around it, you'll need to run the
coroutine's code inside a pcall. When you resume it, the pcall will
catch the error rather than causing the whole coroutine to terminate.
(errors/pcall are Lua's exceptions/try/catch mechanism:
if pcall(coroutine_really_main) then
return coroutine_main() -- restart the coroutine