lua-users home
lua-l archive

RE: customizable Lua "panic" behavior

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


> | This is the only solution I've actually liked thus far. It 
> is easy to 
> | envision something like:
> | 
> | void RunMain()
> | {
> | // All app code that would've been in main() goes here.
> | }
> | 
> | static int StartExecution(lua_State *L)
> | {
> | RunMain();
> | return 0;
> | }
> | 
> | int main()
> | {
> | lua_pushcfunction(L, StartExecution);
> | lua_call(0,0);
> | }
> |
> Do you remove the exit call with this? or are you saying it 
> will never be called? I can understand trapping exceptions, 
> but if an exception occurs, your Lua mem really may be 
> totally hosed. Calling lua_close() would have unpredictable 
> results. Maybe i'm not following you here...
Based on what Edgar said and what I understand about Lua, exit()
shouldn't get called. luaD_breakrun() is the only place exit() can get
called.
void luaD_breakrun (lua_State *L, int errcode) {
 if (L->errorJmp) {
 L->errorJmp->status = errcode;
 longjmp(L->errorJmp->b, 1);
 }
 else {
 if (errcode != LUA_ERRMEM)
 message(L, l_s("unable to recover; exiting\n"));
 exit(EXIT_FAILURE);
 }
}
lua_call() calls luaD_runprotected() which immediately sets up the
L->errorJmp. That being the case, it appears to me that exit() will
never be called in the middle of a lua_call(), thereby making a pretty
slick Lua "exception" handler.
Josh

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