diff options
| -rw-r--r-- | ldo.c | 21 | ||||
| -rw-r--r-- | ltests.c | 11 |
2 files changed, 28 insertions, 4 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.216 2003/02/28 19:45:15 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.217 2003/04/03 13:35:34 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -39,6 +39,20 @@ | |||
| 39 | */ | 39 | */ |
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | #ifndef LUA_USEEXCEPTIONS | ||
| 43 | |||
| 44 | #define L_THROW(c) longjmp((c)->b, 1) | ||
| 45 | #define L_TRY(c,a) if (setjmp((c)->b) == 0) { a } | ||
| 46 | |||
| 47 | #else | ||
| 48 | |||
| 49 | #define L_THROW(c) throw(c) | ||
| 50 | #define L_TRY(c,a) try { a } catch(...) \ | ||
| 51 | { if ((c)->status == 0) (c)->status = -1; } | ||
| 52 | |||
| 53 | #endif | ||
| 54 | |||
| 55 | |||
| 42 | /* chain list of long jump buffers */ | 56 | /* chain list of long jump buffers */ |
| 43 | struct lua_longjmp { | 57 | struct lua_longjmp { |
| 44 | struct lua_longjmp *previous; | 58 | struct lua_longjmp *previous; |
| @@ -70,7 +84,7 @@ static void seterrorobj (lua_State *L, int errcode, StkId oldtop) { | |||
| 70 | void luaD_throw (lua_State *L, int errcode) { | 84 | void luaD_throw (lua_State *L, int errcode) { |
| 71 | if (L->errorJmp) { | 85 | if (L->errorJmp) { |
| 72 | L->errorJmp->status = errcode; | 86 | L->errorJmp->status = errcode; |
| 73 | longjmp(L->errorJmp->b, 1); | 87 | L_THROW(L->errorJmp); |
| 74 | } | 88 | } |
| 75 | else { | 89 | else { |
| 76 | G(L)->panic(L); | 90 | G(L)->panic(L); |
| @@ -84,8 +98,9 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { | |||
| 84 | lj.status = 0; | 98 | lj.status = 0; |
| 85 | lj.previous = L->errorJmp; /* chain new error handler */ | 99 | lj.previous = L->errorJmp; /* chain new error handler */ |
| 86 | L->errorJmp = &lj; | 100 | L->errorJmp = &lj; |
| 87 | if (setjmp(lj.b) == 0) | 101 | L_TRY(&lj, |
| 88 | (*f)(L, ud); | 102 | (*f)(L, ud); |
| 103 | ); | ||
| 89 | L->errorJmp = lj.previous; /* restore old error handler */ | 104 | L->errorJmp = lj.previous; /* restore old error handler */ |
| 90 | return lj.status; | 105 | return lj.status; |
| 91 | } | 106 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 1.158 2003/04/07 14:35:00 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.159 2003/04/28 19:58:06 roberto Exp roberto $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -733,6 +733,15 @@ static int testC (lua_State *L) { | |||
| 733 | luaL_setn(L, i, n); | 733 | luaL_setn(L, i, n); |
| 734 | lua_pop(L, 1); | 734 | lua_pop(L, 1); |
| 735 | } | 735 | } |
| 736 | else if EQ("throw") { | ||
| 737 | #ifdef _cplusplus | ||
| 738 | static struct X { int x; } x; | ||
| 739 | throw x; | ||
| 740 | #else | ||
| 741 | luaL_error(L, "C++"); | ||
| 742 | #endif | ||
| 743 | break; | ||
| 744 | } | ||
| 736 | else luaL_error(L, "unknown instruction %s", buff); | 745 | else luaL_error(L, "unknown instruction %s", buff); |
| 737 | } | 746 | } |
| 738 | return 0; | 747 | return 0; |
