diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-11-27 07:58:04 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-11-27 07:58:04 +0000 |
| commit | 7c97e8e40aaa665226fb54449773dc3134e755b2 (patch) | |
| tree | 47888d4c924fc24bf3b355bf58120ea3cdc74bc4 /src/except.c | |
| parent | eb0fc857ddea6f084d338589e2a33d3e7d4eade6 (diff) | |
| download | luasocket-7c97e8e40aaa665226fb54449773dc3134e755b2.tar.gz luasocket-7c97e8e40aaa665226fb54449773dc3134e755b2.tar.bz2 luasocket-7c97e8e40aaa665226fb54449773dc3134e755b2.zip | |
Almost ready for beta3
Diffstat (limited to 'src/except.c')
| -rw-r--r-- | src/except.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/except.c b/src/except.c index 80d7e5d..dabaf19 100644 --- a/src/except.c +++ b/src/except.c | |||
| @@ -29,11 +29,21 @@ static luaL_reg func[] = { | |||
| 29 | /*-------------------------------------------------------------------------*\ | 29 | /*-------------------------------------------------------------------------*\ |
| 30 | * Try factory | 30 | * Try factory |
| 31 | \*-------------------------------------------------------------------------*/ | 31 | \*-------------------------------------------------------------------------*/ |
| 32 | static void wrap(lua_State *L) { | ||
| 33 | lua_newtable(L); | ||
| 34 | lua_pushnumber(L, 1); | ||
| 35 | lua_pushvalue(L, -3); | ||
| 36 | lua_settable(L, -3); | ||
| 37 | lua_insert(L, -2); | ||
| 38 | lua_pop(L, 1); | ||
| 39 | } | ||
| 40 | |||
| 32 | static int finalize(lua_State *L) { | 41 | static int finalize(lua_State *L) { |
| 33 | if (!lua_toboolean(L, 1)) { | 42 | if (!lua_toboolean(L, 1)) { |
| 34 | lua_pushvalue(L, lua_upvalueindex(1)); | 43 | lua_pushvalue(L, lua_upvalueindex(1)); |
| 35 | lua_pcall(L, 0, 0, 0); | 44 | lua_pcall(L, 0, 0, 0); |
| 36 | lua_settop(L, 2); | 45 | lua_settop(L, 2); |
| 46 | wrap(L); | ||
| 37 | lua_error(L); | 47 | lua_error(L); |
| 38 | return 0; | 48 | return 0; |
| 39 | } else return lua_gettop(L); | 49 | } else return lua_gettop(L); |
| @@ -54,13 +64,23 @@ static int global_newtry(lua_State *L) { | |||
| 54 | /*-------------------------------------------------------------------------*\ | 64 | /*-------------------------------------------------------------------------*\ |
| 55 | * Protect factory | 65 | * Protect factory |
| 56 | \*-------------------------------------------------------------------------*/ | 66 | \*-------------------------------------------------------------------------*/ |
| 67 | static int unwrap(lua_State *L) { | ||
| 68 | if (lua_istable(L, -1)) { | ||
| 69 | lua_pushnumber(L, 1); | ||
| 70 | lua_gettable(L, -2); | ||
| 71 | lua_pushnil(L); | ||
| 72 | lua_insert(L, -2); | ||
| 73 | return 1; | ||
| 74 | } else return 0; | ||
| 75 | } | ||
| 76 | |||
| 57 | static int protected_(lua_State *L) { | 77 | static int protected_(lua_State *L) { |
| 58 | lua_pushvalue(L, lua_upvalueindex(1)); | 78 | lua_pushvalue(L, lua_upvalueindex(1)); |
| 59 | lua_insert(L, 1); | 79 | lua_insert(L, 1); |
| 60 | if (lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0) != 0) { | 80 | if (lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0) != 0) { |
| 61 | lua_pushnil(L); | 81 | if (unwrap(L)) return 2; |
| 62 | lua_insert(L, 1); | 82 | else lua_error(L); |
| 63 | return 2; | 83 | return 0; |
| 64 | } else return lua_gettop(L); | 84 | } else return lua_gettop(L); |
| 65 | } | 85 | } |
| 66 | 86 | ||
