diff options
author | Philipp Janda <siffiejoe@gmx.net> | 2016-02-24 00:57:42 +0100 |
---|---|---|
committer | Philipp Janda <siffiejoe@gmx.net> | 2016-02-24 00:57:42 +0100 |
commit | 4392bdcdd40dd433fc8bf4347653ce1a796cb572 (patch) | |
tree | ca2422a9445dced35fc56518647a446cd86ecc84 | |
parent | 9fe38c654f6c62a4f11d993bd79c710af9313fbd (diff) | |
download | luasocket-4392bdcdd40dd433fc8bf4347653ce1a796cb572.tar.gz luasocket-4392bdcdd40dd433fc8bf4347653ce1a796cb572.tar.bz2 luasocket-4392bdcdd40dd433fc8bf4347653ce1a796cb572.zip |
Always put metatable in first upvalue.
-rw-r--r-- | src/except.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/except.c b/src/except.c index 309f8f0..60b5005 100644 --- a/src/except.c +++ b/src/except.c | |||
@@ -42,13 +42,13 @@ static void wrap(lua_State *L) { | |||
42 | lua_createtable(L, 1, 0); | 42 | lua_createtable(L, 1, 0); |
43 | lua_pushvalue(L, -2); | 43 | lua_pushvalue(L, -2); |
44 | lua_rawseti(L, -2, 1); | 44 | lua_rawseti(L, -2, 1); |
45 | lua_pushvalue(L, lua_upvalueindex(2)); | 45 | lua_pushvalue(L, lua_upvalueindex(1)); |
46 | lua_setmetatable(L, -2); | 46 | lua_setmetatable(L, -2); |
47 | } | 47 | } |
48 | 48 | ||
49 | static int finalize(lua_State *L) { | 49 | static int finalize(lua_State *L) { |
50 | if (!lua_toboolean(L, 1)) { | 50 | if (!lua_toboolean(L, 1)) { |
51 | lua_pushvalue(L, lua_upvalueindex(1)); | 51 | lua_pushvalue(L, lua_upvalueindex(2)); |
52 | lua_call(L, 0, 0); | 52 | lua_call(L, 0, 0); |
53 | lua_settop(L, 2); | 53 | lua_settop(L, 2); |
54 | wrap(L); | 54 | wrap(L); |
@@ -66,6 +66,7 @@ static int global_newtry(lua_State *L) { | |||
66 | lua_settop(L, 1); | 66 | lua_settop(L, 1); |
67 | if (lua_isnil(L, 1)) lua_pushcfunction(L, do_nothing); | 67 | if (lua_isnil(L, 1)) lua_pushcfunction(L, do_nothing); |
68 | lua_pushvalue(L, lua_upvalueindex(1)); | 68 | lua_pushvalue(L, lua_upvalueindex(1)); |
69 | lua_insert(L, -2); | ||
69 | lua_pushcclosure(L, finalize, 2); | 70 | lua_pushcclosure(L, finalize, 2); |
70 | return 1; | 71 | return 1; |
71 | } | 72 | } |
@@ -75,7 +76,7 @@ static int global_newtry(lua_State *L) { | |||
75 | \*-------------------------------------------------------------------------*/ | 76 | \*-------------------------------------------------------------------------*/ |
76 | static int unwrap(lua_State *L) { | 77 | static int unwrap(lua_State *L) { |
77 | if (lua_istable(L, -1) && lua_getmetatable(L, -1)) { | 78 | if (lua_istable(L, -1) && lua_getmetatable(L, -1)) { |
78 | int r = lua_rawequal(L, -1, lua_upvalueindex(2)); | 79 | int r = lua_rawequal(L, -1, lua_upvalueindex(1)); |
79 | lua_pop(L, 1); | 80 | lua_pop(L, 1); |
80 | if (r) { | 81 | if (r) { |
81 | lua_pushnil(L); | 82 | lua_pushnil(L); |
@@ -106,7 +107,7 @@ static int protected_cont(lua_State *L) { | |||
106 | 107 | ||
107 | static int protected_(lua_State *L) { | 108 | static int protected_(lua_State *L) { |
108 | int status; | 109 | int status; |
109 | lua_pushvalue(L, lua_upvalueindex(1)); | 110 | lua_pushvalue(L, lua_upvalueindex(2)); |
110 | lua_insert(L, 1); | 111 | lua_insert(L, 1); |
111 | status = lua_pcallk(L, lua_gettop(L) - 1, LUA_MULTRET, 0, 0, protected_cont); | 112 | status = lua_pcallk(L, lua_gettop(L) - 1, LUA_MULTRET, 0, 0, protected_cont); |
112 | return protected_finish(L, status, 0); | 113 | return protected_finish(L, status, 0); |
@@ -115,6 +116,7 @@ static int protected_(lua_State *L) { | |||
115 | static int global_protect(lua_State *L) { | 116 | static int global_protect(lua_State *L) { |
116 | lua_settop(L, 1); | 117 | lua_settop(L, 1); |
117 | lua_pushvalue(L, lua_upvalueindex(1)); | 118 | lua_pushvalue(L, lua_upvalueindex(1)); |
119 | lua_insert(L, 1); | ||
118 | lua_pushcclosure(L, protected_, 2); | 120 | lua_pushcclosure(L, protected_, 2); |
119 | return 1; | 121 | return 1; |
120 | } | 122 | } |