aboutsummaryrefslogtreecommitdiff
path: root/src/except.c
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-06-18 21:41:44 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-06-18 21:41:44 +0000
commit7ed89c97f760600df238f9853ee453570935870f (patch)
treea17573a43815071e35f85557519fefca739ef7ef /src/except.c
parentac4aac0909da26befaaeb6b415f66cf35b6980e0 (diff)
downloadluasocket-7ed89c97f760600df238f9853ee453570935870f.tar.gz
luasocket-7ed89c97f760600df238f9853ee453570935870f.tar.bz2
luasocket-7ed89c97f760600df238f9853ee453570935870f.zip
2.0 alpha RELEASED!
Diffstat (limited to 'src/except.c')
-rw-r--r--src/except.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/except.c b/src/except.c
index 53a65ac..68abf70 100644
--- a/src/except.c
+++ b/src/except.c
@@ -12,33 +12,21 @@
12/*=========================================================================*\ 12/*=========================================================================*\
13* Internal function prototypes. 13* Internal function prototypes.
14\*=========================================================================*/ 14\*=========================================================================*/
15static int global_try(lua_State *L);
16static int global_protect(lua_State *L); 15static int global_protect(lua_State *L);
17static int global_newtry(lua_State *L); 16static int global_newtry(lua_State *L);
18static int protected(lua_State *L); 17static int protected(lua_State *L);
19static int finalize(lua_State *L); 18static int finalize(lua_State *L);
19static int do_nothing(lua_State *L);
20 20
21/* except functions */ 21/* except functions */
22static luaL_reg func[] = { 22static luaL_reg func[] = {
23 {"try", global_try},
24 {"newtry", global_newtry}, 23 {"newtry", global_newtry},
25 {"protect", global_protect}, 24 {"protect", global_protect},
26 {NULL, NULL} 25 {NULL, NULL}
27}; 26};
28 27
29/*-------------------------------------------------------------------------*\ 28/*-------------------------------------------------------------------------*\
30* Try method 29* Try factory
31\*-------------------------------------------------------------------------*/
32static int global_try(lua_State *L) {
33 if (lua_isnil(L, 1) || (lua_isboolean(L, 1) && !lua_toboolean(L, 1))) {
34 lua_settop(L, 2);
35 lua_error(L);
36 return 0;
37 } else return lua_gettop(L);
38}
39
40/*-------------------------------------------------------------------------*\
41* Finalizer factory
42\*-------------------------------------------------------------------------*/ 30\*-------------------------------------------------------------------------*/
43static int finalize(lua_State *L) { 31static int finalize(lua_State *L) {
44 if (lua_isnil(L, 1) || (lua_isboolean(L, 1) && !lua_toboolean(L, 1))) { 32 if (lua_isnil(L, 1) || (lua_isboolean(L, 1) && !lua_toboolean(L, 1))) {
@@ -50,7 +38,14 @@ static int finalize(lua_State *L) {
50 } else return lua_gettop(L); 38 } else return lua_gettop(L);
51} 39}
52 40
41static int do_nothing(lua_State *L) {
42 (void) L;
43 return 0;
44}
45
53static int global_newtry(lua_State *L) { 46static int global_newtry(lua_State *L) {
47 lua_settop(L, 1);
48 if (lua_isnil(L, 1)) lua_pushcfunction(L, do_nothing);
54 lua_pushcclosure(L, finalize, 1); 49 lua_pushcclosure(L, finalize, 1);
55 return 1; 50 return 1;
56} 51}