diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-08-21 14:43:44 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-08-21 14:43:44 -0300 |
commit | cc117253c83ec32d226a8f2226d5ca144804f873 (patch) | |
tree | 46551b01d3febf98d65d55276d5831a75e2e0062 /ldo.c | |
parent | 8e226e6a09390a80fde98f192833fc85a5537376 (diff) | |
download | lua-cc117253c83ec32d226a8f2226d5ca144804f873.tar.gz lua-cc117253c83ec32d226a8f2226d5ca144804f873.tar.bz2 lua-cc117253c83ec32d226a8f2226d5ca144804f873.zip |
new implementation for error handling: on error, function _ERRORMESSAGE
is called, which in turn calls _ALERT to write a message to stderr.
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 33 |
1 files changed, 11 insertions, 22 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.27 1998/06/19 18:47:06 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.28 1998/07/12 16:14: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 | */ |
@@ -17,6 +17,7 @@ | |||
17 | #include "lobject.h" | 17 | #include "lobject.h" |
18 | #include "lparser.h" | 18 | #include "lparser.h" |
19 | #include "lstate.h" | 19 | #include "lstate.h" |
20 | #include "lstring.h" | ||
20 | #include "ltm.h" | 21 | #include "ltm.h" |
21 | #include "lua.h" | 22 | #include "lua.h" |
22 | #include "luadebug.h" | 23 | #include "luadebug.h" |
@@ -32,27 +33,13 @@ | |||
32 | 33 | ||
33 | 34 | ||
34 | 35 | ||
35 | /* | ||
36 | ** Error messages | ||
37 | */ | ||
38 | |||
39 | static void stderrorim (void) | ||
40 | { | ||
41 | fprintf(stderr, "lua error: %s\n", lua_getstring(lua_getparam(1))); | ||
42 | } | ||
43 | |||
44 | |||
45 | |||
46 | #define STACK_UNIT 128 | 36 | #define STACK_UNIT 128 |
47 | 37 | ||
48 | 38 | ||
49 | void luaD_init (void) | 39 | void luaD_init (void) { |
50 | { | ||
51 | L->stack.stack = luaM_newvector(STACK_UNIT, TObject); | 40 | L->stack.stack = luaM_newvector(STACK_UNIT, TObject); |
52 | L->stack.top = L->stack.stack; | 41 | L->stack.top = L->stack.stack; |
53 | L->stack.last = L->stack.stack+(STACK_UNIT-1); | 42 | L->stack.last = L->stack.stack+(STACK_UNIT-1); |
54 | ttype(&L->errorim) = LUA_T_CPROTO; | ||
55 | fvalue(&L->errorim) = stderrorim; | ||
56 | } | 43 | } |
57 | 44 | ||
58 | 45 | ||
@@ -246,12 +233,13 @@ void luaD_travstack (int (*fn)(TObject *)) | |||
246 | 233 | ||
247 | 234 | ||
248 | 235 | ||
249 | static void message (char *s) | 236 | static void message (char *s) { |
250 | { | 237 | TObject *em = &(luaS_new("_ERRORMESSAGE")->u.s.globalval); |
251 | TObject im = L->errorim; | 238 | if (ttype(em) != LUA_T_NIL) { |
252 | if (ttype(&im) != LUA_T_NIL) { | 239 | *L->stack.top = *em; |
240 | incr_top; | ||
253 | lua_pushstring(s); | 241 | lua_pushstring(s); |
254 | luaD_callTM(&im, 1, 0); | 242 | luaD_calln(1, 0); |
255 | } | 243 | } |
256 | } | 244 | } |
257 | 245 | ||
@@ -264,7 +252,8 @@ void lua_error (char *s) | |||
264 | if (L->errorJmp) | 252 | if (L->errorJmp) |
265 | longjmp(*((jmp_buf *)L->errorJmp), 1); | 253 | longjmp(*((jmp_buf *)L->errorJmp), 1); |
266 | else { | 254 | else { |
267 | fprintf (stderr, "lua: exit(1). Unable to recover\n"); | 255 | lua_pushstring("lua: exit(1). Unable to recover.\n"); |
256 | lua_call("_ALERT"); | ||
268 | exit(1); | 257 | exit(1); |
269 | } | 258 | } |
270 | } | 259 | } |