|
understood, thanks for help. > Date: Wed, 10 Dec 2008 11:13:53 +0000 > From: dg@cowlark.com > To: lua@bazar2.conectiva.com.br > Subject: Re: how to clear error info from a state? > > 吕游 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_fu nction_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 > MSN热搜榜全新升级,更多排行榜等着你! 立即查看! |