lua-users home
lua-l archive

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


cool. Thanks guys, i'll try this out. I'd much prefer something 
like this to modifying the vm. I really like these new error
returns. Now if I could just get over not having lua_Object... :)


Regards,
Jim

----- Original Message ----- 
From: "Joshua Jensen" <jjensen@workspacewhiz.com>
To: "Multiple recipients of list" <lua-l@tecgraf.puc-rio.br>
Sent: Monday, November 19, 2001 11:08 PM
Subject: RE: customizable Lua "panic" behavior


| > | 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
| 
|