[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: how to clear error info from a state?
- From: David Given <dg@...>
- Date: Wed, 10 Dec 2008 11:13:53 +0000
吕游 wrote:
> 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:
function coroutine_really_main()
call_some_native_function_that_may_error()
end
function coroutine_main()
if pcall(coroutine_really_main) then
success()
else
cleanup_after_error()
return coroutine_main() -- restart the coroutine
end
end
--
David Given
dg@cowlark.com