aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-05-13 16:22:19 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-05-13 16:22:19 -0300
commitc7677471918fa55095f4993484eb5805091364fd (patch)
treee916682119d3aebe6a8fae9ac4ab092b5f28f98c /ldo.c
parentf966404ed636c1e61b4ab5ee5e7715739cc4ab49 (diff)
downloadlua-c7677471918fa55095f4993484eb5805091364fd.tar.gz
lua-c7677471918fa55095f4993484eb5805091364fd.tar.bz2
lua-c7677471918fa55095f4993484eb5805091364fd.zip
new (internal) macros for error handling
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/ldo.c b/ldo.c
index 6dbfe833..9c5f7f3a 100644
--- a/ldo.c
+++ b/ldo.c
@@ -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 */
43struct lua_longjmp { 57struct 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) {
70void luaD_throw (lua_State *L, int errcode) { 84void 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}