lua-users home
lua-l archive

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

> I apologise for being not quite in context, so my question may be a
> silly one. I see the expected use case of this feature roughly as
> follows (pseudocode):
> 1. [worker thread] spawn_watchdog_thread(L); lua_pcall(L, <stuff>);
> stop_watchdog_thread();
> 2. [watchdog thread] if (spent_too_much_time()) lua_forcereturn(L, 1);
> If forcereturn is triggered, lua_pcall() returns (prematurely) in
> worker thread, and worker thread execution continues as usual.
> The question: How would worker thread know that lua_pcall() returned
> due to lua_forcereturn() call somewhere (except that it may ask the
> watchdog thread)?
> I'd expect some LUA_ERRFORCED return code -- anyway, this is an error
> scenario, since our script presumably was stopped somewhere in the
> middle. Would I be able to reuse the Lua state after lua_(p)call() was
> "forcereturned"? If not, then how is such forcereturning different
> from, say, just calling lua_panic() righ after it was detected that
> forcereturn flag was set?

I fail to see the need for lua_forcereturn: you can just use lua_error.
Remember the Lua can raise errors on any Lua value, not just strings.
A suitable error value can be used to transmit any info on the cause
of error.