aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-04-22 11:40:23 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-04-22 11:40:23 -0300
commitf388ee4a822b3d8027ed7c28aa21e9406e4a11eb (patch)
tree33053e6e31ac1dee0fe27ff7fdba64325a624fe1
parent30ad4c75db38639f52fb1c8be1c5a3f5b58e776f (diff)
downloadlua-f388ee4a822b3d8027ed7c28aa21e9406e4a11eb.tar.gz
lua-f388ee4a822b3d8027ed7c28aa21e9406e4a11eb.tar.bz2
lua-f388ee4a822b3d8027ed7c28aa21e9406e4a11eb.zip
new way to handle errors
-rw-r--r--lbaselib.c12
-rw-r--r--ldebug.c4
-rw-r--r--lmem.c8
-rw-r--r--lobject.c4
-rw-r--r--lstate.c4
-rw-r--r--ltable.c8
-rw-r--r--lua.h10
-rw-r--r--lvm.c16
8 files changed, 32 insertions, 34 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 227d576c..d6168294 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.67 2002/04/12 19:57:29 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.68 2002/04/15 20:54:41 roberto Exp roberto $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -280,7 +280,7 @@ static int aux_unpack (lua_State *L, int arg) {
280 int n, i; 280 int n, i;
281 luaL_check_type(L, arg, LUA_TTABLE); 281 luaL_check_type(L, arg, LUA_TTABLE);
282 n = lua_getn(L, arg); 282 n = lua_getn(L, arg);
283 luaL_check_stack(L, n, "table too big to unpack"); 283 luaL_check_stack(L, n+LUA_MINSTACK, "table too big to unpack");
284 for (i=1; i<=n; i++) /* push arg[1...n] */ 284 for (i=1; i<=n; i++) /* push arg[1...n] */
285 lua_rawgeti(L, arg, i); 285 lua_rawgeti(L, arg, i);
286 return n; 286 return n;
@@ -299,10 +299,10 @@ static int luaB_call (lua_State *L) {
299 int status; 299 int status;
300 int n; 300 int n;
301 if (!lua_isnone(L, 4)) { /* set new error method */ 301 if (!lua_isnone(L, 4)) { /* set new error method */
302 lua_getglobal(L, LUA_ERRORMESSAGE); 302 lua_getglobal(L, "_ERRORMESSAGE");
303 err = lua_gettop(L); /* get index */ 303 err = lua_gettop(L); /* get index */
304 lua_pushvalue(L, 4); 304 lua_pushvalue(L, 4);
305 lua_setglobal(L, LUA_ERRORMESSAGE); 305 lua_setglobal(L, "_ERRORMESSAGE");
306 } 306 }
307 oldtop = lua_gettop(L); /* top before function-call preparation */ 307 oldtop = lua_gettop(L); /* top before function-call preparation */
308 /* push function */ 308 /* push function */
@@ -311,7 +311,7 @@ static int luaB_call (lua_State *L) {
311 status = lua_call(L, n, LUA_MULTRET); 311 status = lua_call(L, n, LUA_MULTRET);
312 if (err != 0) { /* restore old error method */ 312 if (err != 0) { /* restore old error method */
313 lua_pushvalue(L, err); 313 lua_pushvalue(L, err);
314 lua_setglobal(L, LUA_ERRORMESSAGE); 314 lua_setglobal(L, "_ERRORMESSAGE");
315 } 315 }
316 if (status != 0) { /* error in call? */ 316 if (status != 0) { /* error in call? */
317 if (strchr(options, 'x')) 317 if (strchr(options, 'x'))
@@ -460,7 +460,7 @@ static int luaB_require (lua_State *L) {
460 460
461static const luaL_reg base_funcs[] = { 461static const luaL_reg base_funcs[] = {
462 {LUA_ALERT, luaB__ALERT}, 462 {LUA_ALERT, luaB__ALERT},
463 {LUA_ERRORMESSAGE, luaB__ERRORMESSAGE}, 463 {"_ERRORMESSAGE", luaB__ERRORMESSAGE},
464 {"error", luaB_error}, 464 {"error", luaB_error},
465 {"metatable", luaB_metatable}, 465 {"metatable", luaB_metatable},
466 {"globals", luaB_globals}, 466 {"globals", luaB_globals},
diff --git a/ldebug.c b/ldebug.c
index b34e6fff..2fa719ee 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.107 2002/04/09 19:47:44 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.108 2002/04/10 12:11:07 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -144,7 +144,7 @@ static void funcinfo (lua_State *L, lua_Debug *ar, StkId func) {
144 if (ttype(func) == LUA_TFUNCTION) 144 if (ttype(func) == LUA_TFUNCTION)
145 cl = clvalue(func); 145 cl = clvalue(func);
146 else { 146 else {
147 luaD_error(L, "value for `lua_getinfo' is not a function"); 147 luaD_runerror(L, "value for `lua_getinfo' is not a function");
148 cl = NULL; /* to avoid warnings */ 148 cl = NULL; /* to avoid warnings */
149 } 149 }
150 if (cl->c.isC) { 150 if (cl->c.isC) {
diff --git a/lmem.c b/lmem.c
index 33181016..435cceef 100644
--- a/lmem.c
+++ b/lmem.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmem.c,v 1.51 2001/10/25 19:13:33 roberto Exp $ 2** $Id: lmem.c,v 1.52 2001/11/28 20:13:13 roberto Exp roberto $
3** Interface to Memory Manager 3** Interface to Memory Manager
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -34,7 +34,7 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems,
34 else if (*size >= limit/2) { /* cannot double it? */ 34 else if (*size >= limit/2) { /* cannot double it? */
35 if (*size < limit - MINSIZEARRAY) /* try something smaller... */ 35 if (*size < limit - MINSIZEARRAY) /* try something smaller... */
36 newsize = limit; /* still have at least MINSIZEARRAY free places */ 36 newsize = limit; /* still have at least MINSIZEARRAY free places */
37 else luaD_error(L, errormsg); 37 else luaD_runerror(L, errormsg);
38 } 38 }
39 newblock = luaM_realloc(L, block, 39 newblock = luaM_realloc(L, block,
40 cast(lu_mem, *size)*cast(lu_mem, size_elems), 40 cast(lu_mem, *size)*cast(lu_mem, size_elems),
@@ -53,12 +53,12 @@ void *luaM_realloc (lua_State *L, void *block, lu_mem oldsize, lu_mem size) {
53 block = NULL; 53 block = NULL;
54 } 54 }
55 else if (size >= MAX_SIZET) 55 else if (size >= MAX_SIZET)
56 luaD_error(L, "memory allocation error: block too big"); 56 luaD_runerror(L, "memory allocation error: block too big");
57 else { 57 else {
58 block = l_realloc(block, oldsize, size); 58 block = l_realloc(block, oldsize, size);
59 if (block == NULL) { 59 if (block == NULL) {
60 if (L) 60 if (L)
61 luaD_breakrun(L, LUA_ERRMEM); /* break run without error message */ 61 luaD_error(L, NULL, LUA_ERRMEM); /* break run without error message */
62 else return NULL; /* error before creating state! */ 62 else return NULL; /* error before creating state! */
63 } 63 }
64 } 64 }
diff --git a/lobject.c b/lobject.c
index 41b193cf..67e54635 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.75 2002/02/07 17:25:12 roberto Exp roberto $ 2** $Id: lobject.c,v 1.76 2002/04/05 18:54:31 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -97,7 +97,7 @@ void luaO_verror (lua_State *L, const char *fmt, ...) {
97 va_start(argp, fmt); 97 va_start(argp, fmt);
98 vsprintf(buff, fmt, argp); 98 vsprintf(buff, fmt, argp);
99 va_end(argp); 99 va_end(argp);
100 luaD_error(L, buff); 100 luaD_runerror(L, buff);
101} 101}
102 102
103 103
diff --git a/lstate.c b/lstate.c
index 714fac6a..9725bed5 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 1.88 2002/03/20 12:52:32 roberto Exp roberto $ 2** $Id: lstate.c,v 1.89 2002/04/16 17:08:28 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -124,7 +124,7 @@ LUA_API lua_State *lua_open (void) {
124 preinit_state(L); 124 preinit_state(L);
125 L->l_G = NULL; 125 L->l_G = NULL;
126 L->next = L->previous = L; 126 L->next = L->previous = L;
127 if (luaD_runprotected(L, f_luaopen, NULL) != 0) { 127 if (luaD_runprotected(L, f_luaopen, &luaO_nilobject, NULL) != 0) {
128 /* memory allocation error: free partial state */ 128 /* memory allocation error: free partial state */
129 close_state(L); 129 close_state(L);
130 L = NULL; 130 L = NULL;
diff --git a/ltable.c b/ltable.c
index c71179d1..0403f3c2 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.102 2002/03/18 18:18:35 roberto Exp roberto $ 2** $Id: ltable.c,v 1.103 2002/04/05 18:54:31 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -111,7 +111,7 @@ static int luaH_index (lua_State *L, Table *t, const TObject *key) {
111 else { 111 else {
112 const TObject *v = luaH_get(t, key); 112 const TObject *v = luaH_get(t, key);
113 if (v == &luaO_nilobject) 113 if (v == &luaO_nilobject)
114 luaD_error(L, "invalid key for `next'"); 114 luaD_runerror(L, "invalid key for `next'");
115 i = cast(int, (cast(const lu_byte *, v) - 115 i = cast(int, (cast(const lu_byte *, v) -
116 cast(const lu_byte *, val(node(t, 0)))) / sizeof(Node)); 116 cast(const lu_byte *, val(node(t, 0)))) / sizeof(Node));
117 return i + t->sizearray; /* hash elements are numbered after array ones */ 117 return i + t->sizearray; /* hash elements are numbered after array ones */
@@ -220,7 +220,7 @@ static void setnodevector (lua_State *L, Table *t, int lsize) {
220 int size; 220 int size;
221 if (lsize < MINHASHSIZE) lsize = MINHASHSIZE; 221 if (lsize < MINHASHSIZE) lsize = MINHASHSIZE;
222 else if (lsize > MAXBITS) 222 else if (lsize > MAXBITS)
223 luaD_error(L, "table overflow"); 223 luaD_runerror(L, "table overflow");
224 size = twoto(lsize); 224 size = twoto(lsize);
225 t->node = luaM_newvector(L, size, Node); 225 t->node = luaM_newvector(L, size, Node);
226 for (i=0; i<size; i++) { 226 for (i=0; i<size; i++) {
@@ -441,7 +441,7 @@ void luaH_set (lua_State *L, Table *t, const TObject *key, const TObject *val) {
441 settableval(p, val); 441 settableval(p, val);
442 } 442 }
443 else { 443 else {
444 if (ttype(key) == LUA_TNIL) luaD_error(L, "table index is nil"); 444 if (ttype(key) == LUA_TNIL) luaD_runerror(L, "table index is nil");
445 newkey(L, t, key, val); 445 newkey(L, t, key, val);
446 } 446 }
447 t->flags = 0; 447 t->flags = 0;
diff --git a/lua.h b/lua.h
index 4764e1d1..52db9d61 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.126 2002/04/05 18:54:31 roberto Exp roberto $ 2** $Id: lua.h,v 1.127 2002/04/16 17:08:28 roberto Exp roberto $
3** Lua - An Extensible Extension Language 3** Lua - An Extensible Extension Language
4** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil 4** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
5** e-mail: info@lua.org 5** e-mail: info@lua.org
@@ -22,9 +22,6 @@
22#define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo" 22#define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"
23 23
24 24
25/* name of global variable with error handler */
26#define LUA_ERRORMESSAGE "_ERRORMESSAGE"
27
28 25
29/* option for multiple returns in `lua_call' */ 26/* option for multiple returns in `lua_call' */
30#define LUA_MULTRET (-1) 27#define LUA_MULTRET (-1)
@@ -173,11 +170,12 @@ LUA_API void lua_setmetatable (lua_State *L, int objindex);
173*/ 170*/
174LUA_API int lua_call (lua_State *L, int nargs, int nresults); 171LUA_API int lua_call (lua_State *L, int nargs, int nresults);
175LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults); 172LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults);
173LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errf);
176LUA_API int lua_loadfile (lua_State *L, const char *filename); 174LUA_API int lua_loadfile (lua_State *L, const char *filename);
177LUA_API int lua_dofile (lua_State *L, const char *filename);
178LUA_API int lua_dostring (lua_State *L, const char *str);
179LUA_API int lua_loadbuffer (lua_State *L, const char *buff, size_t size, 175LUA_API int lua_loadbuffer (lua_State *L, const char *buff, size_t size,
180 const char *name); 176 const char *name);
177LUA_API int lua_dofile (lua_State *L, const char *filename);
178LUA_API int lua_dostring (lua_State *L, const char *str);
181LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, 179LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size,
182 const char *name); 180 const char *name);
183 181
diff --git a/lvm.c b/lvm.c
index 9079b32b..a8f8d983 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.224 2002/04/09 19:47:44 roberto Exp roberto $ 2** $Id: lvm.c,v 1.225 2002/04/10 12:11:07 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -134,7 +134,7 @@ void luaV_gettable (lua_State *L, const TObject *t, TObject *key, StkId res) {
134 if (ttype(tm) == LUA_TFUNCTION) 134 if (ttype(tm) == LUA_TFUNCTION)
135 callTMres(L, tm, t, key, res); 135 callTMres(L, tm, t, key, res);
136 else { 136 else {
137 if (++loop == MAXTAGLOOP) luaD_error(L, "loop in gettable"); 137 if (++loop == MAXTAGLOOP) luaD_runerror(L, "loop in gettable");
138 t = tm; 138 t = tm;
139 goto init; /* return luaV_gettable(L, tm, key, res); */ 139 goto init; /* return luaV_gettable(L, tm, key, res); */
140 } 140 }
@@ -164,7 +164,7 @@ void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) {
164 if (ttype(tm) == LUA_TFUNCTION) 164 if (ttype(tm) == LUA_TFUNCTION)
165 callTM(L, tm, t, key, val); 165 callTM(L, tm, t, key, val);
166 else { 166 else {
167 if (++loop == MAXTAGLOOP) luaD_error(L, "loop in settable"); 167 if (++loop == MAXTAGLOOP) luaD_runerror(L, "loop in settable");
168 t = tm; 168 t = tm;
169 goto init; /* luaV_settable(L, tm, key, val); */ 169 goto init; /* luaV_settable(L, tm, key, val); */
170 } 170 }
@@ -241,7 +241,7 @@ void luaV_strconc (lua_State *L, int total, int last) {
241 tl += tsvalue(top-n-1)->tsv.len; 241 tl += tsvalue(top-n-1)->tsv.len;
242 n++; 242 n++;
243 } 243 }
244 if (tl > MAX_SIZET) luaD_error(L, "string size overflow"); 244 if (tl > MAX_SIZET) luaD_runerror(L, "string size overflow");
245 buffer = luaO_openspace(L, tl, char); 245 buffer = luaO_openspace(L, tl, char);
246 tl = 0; 246 tl = 0;
247 for (i=n; i>0; i--) { /* concat all strings */ 247 for (i=n; i>0; i--) { /* concat all strings */
@@ -266,7 +266,7 @@ static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) {
266 setsvalue(&o, luaS_newliteral(L, "pow")); 266 setsvalue(&o, luaS_newliteral(L, "pow"));
267 luaV_gettable(L, gt(L), &o, &f); 267 luaV_gettable(L, gt(L), &o, &f);
268 if (ttype(&f) != LUA_TFUNCTION) 268 if (ttype(&f) != LUA_TFUNCTION)
269 luaD_error(L, "`pow' (for `^' operator) is not a function"); 269 luaD_runerror(L, "`pow' (for `^' operator) is not a function");
270 callTMres(L, &f, b, c, ra); 270 callTMres(L, &f, b, c, ra);
271 } 271 }
272 else 272 else
@@ -535,11 +535,11 @@ StkId luaV_execute (lua_State *L) {
535 const TObject *plimit = ra+1; 535 const TObject *plimit = ra+1;
536 const TObject *pstep = ra+2; 536 const TObject *pstep = ra+2;
537 if (ttype(ra) != LUA_TNUMBER) 537 if (ttype(ra) != LUA_TNUMBER)
538 luaD_error(L, "`for' initial value must be a number"); 538 luaD_runerror(L, "`for' initial value must be a number");
539 if (!tonumber(plimit, ra+1)) 539 if (!tonumber(plimit, ra+1))
540 luaD_error(L, "`for' limit must be a number"); 540 luaD_runerror(L, "`for' limit must be a number");
541 if (!tonumber(pstep, ra+2)) 541 if (!tonumber(pstep, ra+2))
542 luaD_error(L, "`for' step must be a number"); 542 luaD_runerror(L, "`for' step must be a number");
543 step = nvalue(pstep); 543 step = nvalue(pstep);
544 index = nvalue(ra) + step; /* increment index */ 544 index = nvalue(ra) + step; /* increment index */
545 limit = nvalue(plimit); 545 limit = nvalue(plimit);