aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lbaselib.c16
-rw-r--r--ldo.c14
-rw-r--r--loadlib.c6
-rw-r--r--lstate.c8
-rw-r--r--ltests.c8
-rw-r--r--lua.c50
-rw-r--r--lua.h5
7 files changed, 54 insertions, 53 deletions
diff --git a/lbaselib.c b/lbaselib.c
index a6412d3c..d7413232 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.191 2006/06/02 15:34:00 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.192 2006/09/11 14:07:24 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*/
@@ -264,7 +264,7 @@ static int luaB_ipairs (lua_State *L) {
264 264
265 265
266static int load_aux (lua_State *L, int status) { 266static int load_aux (lua_State *L, int status) {
267 if (status == 0) /* OK? */ 267 if (status == LUA_OK)
268 return 1; 268 return 1;
269 else { 269 else {
270 lua_pushnil(L); 270 lua_pushnil(L);
@@ -325,7 +325,7 @@ static int luaB_load (lua_State *L) {
325static int luaB_dofile (lua_State *L) { 325static int luaB_dofile (lua_State *L) {
326 const char *fname = luaL_optstring(L, 1, NULL); 326 const char *fname = luaL_optstring(L, 1, NULL);
327 int n = lua_gettop(L); 327 int n = lua_gettop(L);
328 if (luaL_loadfile(L, fname) != 0) lua_error(L); 328 if (luaL_loadfile(L, fname) != LUA_OK) lua_error(L);
329 lua_call(L, 0, LUA_MULTRET); 329 lua_call(L, 0, LUA_MULTRET);
330 return lua_gettop(L) - n; 330 return lua_gettop(L) - n;
331} 331}
@@ -373,7 +373,7 @@ static int luaB_pcall (lua_State *L) {
373 int status; 373 int status;
374 luaL_checkany(L, 1); 374 luaL_checkany(L, 1);
375 status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0); 375 status = lua_pcall(L, lua_gettop(L) - 1, LUA_MULTRET, 0);
376 lua_pushboolean(L, (status == 0)); 376 lua_pushboolean(L, (status == LUA_OK));
377 lua_insert(L, 1); 377 lua_insert(L, 1);
378 return lua_gettop(L); /* return status + all results */ 378 return lua_gettop(L); /* return status + all results */
379} 379}
@@ -385,7 +385,7 @@ static int luaB_xpcall (lua_State *L) {
385 lua_settop(L, 2); 385 lua_settop(L, 2);
386 lua_insert(L, 1); /* put error function under function to be called */ 386 lua_insert(L, 1); /* put error function under function to be called */
387 status = lua_pcall(L, 0, LUA_MULTRET, 1); 387 status = lua_pcall(L, 0, LUA_MULTRET, 1);
388 lua_pushboolean(L, (status == 0)); 388 lua_pushboolean(L, (status == LUA_OK));
389 lua_replace(L, 1); 389 lua_replace(L, 1);
390 return lua_gettop(L); /* return status + all results */ 390 return lua_gettop(L); /* return status + all results */
391} 391}
@@ -481,13 +481,13 @@ static int auxresume (lua_State *L, lua_State *co, int narg) {
481 int status; 481 int status;
482 if (!lua_checkstack(co, narg)) 482 if (!lua_checkstack(co, narg))
483 luaL_error(L, "too many arguments to resume"); 483 luaL_error(L, "too many arguments to resume");
484 if (lua_status(co) == 0 && lua_gettop(co) == 0) { 484 if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) {
485 lua_pushliteral(L, "cannot resume dead coroutine"); 485 lua_pushliteral(L, "cannot resume dead coroutine");
486 return -1; /* error flag */ 486 return -1; /* error flag */
487 } 487 }
488 lua_xmove(L, co, narg); 488 lua_xmove(L, co, narg);
489 status = lua_resume(co, narg); 489 status = lua_resume(co, narg);
490 if (status == 0 || status == LUA_YIELD) { 490 if (status == LUA_OK || status == LUA_YIELD) {
491 int nres = lua_gettop(co); 491 int nres = lua_gettop(co);
492 if (!lua_checkstack(L, nres)) 492 if (!lua_checkstack(L, nres))
493 luaL_error(L, "too many results to resume"); 493 luaL_error(L, "too many results to resume");
@@ -565,7 +565,7 @@ static int luaB_costatus (lua_State *L) {
565 case LUA_YIELD: 565 case LUA_YIELD:
566 lua_pushliteral(L, "suspended"); 566 lua_pushliteral(L, "suspended");
567 break; 567 break;
568 case 0: { 568 case LUA_OK: {
569 lua_Debug ar; 569 lua_Debug ar;
570 if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ 570 if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */
571 lua_pushliteral(L, "normal"); /* it is running */ 571 lua_pushliteral(L, "normal"); /* it is running */
diff --git a/ldo.c b/ldo.c
index d0fd01ef..86a9c986 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.42 2006/09/11 14:07:24 roberto Exp roberto $ 2** $Id: ldo.c,v 2.43 2006/09/19 13:57:50 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*/
@@ -110,7 +110,7 @@ void luaD_throw (lua_State *L, int errcode) {
110int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { 110int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
111 unsigned short oldnCcalls = G(L)->nCcalls; 111 unsigned short oldnCcalls = G(L)->nCcalls;
112 struct lua_longjmp lj; 112 struct lua_longjmp lj;
113 lj.status = 0; 113 lj.status = LUA_OK;
114 lj.previous = L->errorJmp; /* chain new error handler */ 114 lj.previous = L->errorJmp; /* chain new error handler */
115 L->errorJmp = &lj; 115 L->errorJmp = &lj;
116 LUAI_TRY(L, &lj, 116 LUAI_TRY(L, &lj,
@@ -391,14 +391,14 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
391static void resume (lua_State *L, void *ud) { 391static void resume (lua_State *L, void *ud) {
392 StkId firstArg = cast(StkId, ud); 392 StkId firstArg = cast(StkId, ud);
393 CallInfo *ci = L->ci; 393 CallInfo *ci = L->ci;
394 if (L->status == 0) { /* start coroutine? */ 394 if (L->status == LUA_OK) { /* start coroutine? */
395 lua_assert(ci == L->base_ci && firstArg > L->base); 395 lua_assert(ci == L->base_ci && firstArg > L->base);
396 if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA) 396 if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA)
397 return; 397 return;
398 } 398 }
399 else { /* resuming from previous yield */ 399 else { /* resuming from previous yield */
400 lua_assert(L->status == LUA_YIELD); 400 lua_assert(L->status == LUA_YIELD);
401 L->status = 0; 401 L->status = LUA_OK;
402 if (!f_isLua(ci)) { /* `common' yield? */ 402 if (!f_isLua(ci)) { /* `common' yield? */
403 /* finish interrupted execution of `OP_CALL' */ 403 /* finish interrupted execution of `OP_CALL' */
404 lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || 404 lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL ||
@@ -426,7 +426,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) {
426 int status; 426 int status;
427 lua_lock(L); 427 lua_lock(L);
428 if (L->status != LUA_YIELD) { 428 if (L->status != LUA_YIELD) {
429 if (L->status != 0) 429 if (L->status != LUA_OK)
430 return resume_error(L, "cannot resume dead coroutine"); 430 return resume_error(L, "cannot resume dead coroutine");
431 else if (L->ci != L->base_ci) 431 else if (L->ci != L->base_ci)
432 return resume_error(L, "cannot resume non-suspended coroutine"); 432 return resume_error(L, "cannot resume non-suspended coroutine");
@@ -437,7 +437,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) {
437 return resume_error(L, "C stack overflow"); 437 return resume_error(L, "C stack overflow");
438 L->baseCcalls = ++G(L)->nCcalls; 438 L->baseCcalls = ++G(L)->nCcalls;
439 status = luaD_rawrunprotected(L, resume, L->top - nargs); 439 status = luaD_rawrunprotected(L, resume, L->top - nargs);
440 if (status != 0) { /* error? */ 440 if (status != LUA_OK) { /* error? */
441 L->status = cast_byte(status); /* mark thread as `dead' */ 441 L->status = cast_byte(status); /* mark thread as `dead' */
442 luaD_seterrorobj(L, status, L->top); 442 luaD_seterrorobj(L, status, L->top);
443 L->ci->top = L->top; 443 L->ci->top = L->top;
@@ -473,7 +473,7 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u,
473 ptrdiff_t old_errfunc = L->errfunc; 473 ptrdiff_t old_errfunc = L->errfunc;
474 L->errfunc = ef; 474 L->errfunc = ef;
475 status = luaD_rawrunprotected(L, func, u); 475 status = luaD_rawrunprotected(L, func, u);
476 if (status != 0) { /* an error occurred? */ 476 if (status != LUA_OK) { /* an error occurred? */
477 StkId oldtop = restorestack(L, old_top); 477 StkId oldtop = restorestack(L, old_top);
478 luaF_close(L, oldtop); /* close possible pending closures */ 478 luaF_close(L, oldtop); /* close possible pending closures */
479 luaD_seterrorobj(L, status, oldtop); 479 luaD_seterrorobj(L, status, oldtop);
diff --git a/loadlib.c b/loadlib.c
index 36778891..98d60008 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loadlib.c,v 1.54 2006/07/03 20:16:49 roberto Exp roberto $ 2** $Id: loadlib.c,v 1.55 2006/09/11 14:07:24 roberto Exp roberto $
3** Dynamic library loader for Lua 3** Dynamic library loader for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5** 5**
@@ -89,8 +89,6 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
89** ======================================================================= 89** =======================================================================
90*/ 90*/
91 91
92#include <windows.h>
93
94 92
95#undef setprogdir 93#undef setprogdir
96 94
@@ -382,7 +380,7 @@ static int loader_Lua (lua_State *L) {
382 const char *name = luaL_checkstring(L, 1); 380 const char *name = luaL_checkstring(L, 1);
383 filename = findfile(L, name, "path"); 381 filename = findfile(L, name, "path");
384 if (filename == NULL) return 1; /* library not found in this path */ 382 if (filename == NULL) return 1; /* library not found in this path */
385 if (luaL_loadfile(L, filename) != 0) 383 if (luaL_loadfile(L, filename) != LUA_OK)
386 loaderror(L, filename); 384 loaderror(L, filename);
387 return 1; /* library loaded successfully */ 385 return 1; /* library loaded successfully */
388} 386}
diff --git a/lstate.c b/lstate.c
index 66fffbc9..dc2827c3 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.38 2006/08/15 19:59:20 roberto Exp roberto $ 2** $Id: lstate.c,v 2.39 2006/09/11 14:07:24 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*/
@@ -95,7 +95,7 @@ static void preinit_state (lua_State *L, global_State *g) {
95 L->openupval = NULL; 95 L->openupval = NULL;
96 L->size_ci = 0; 96 L->size_ci = 0;
97 L->baseCcalls = 0; 97 L->baseCcalls = 0;
98 L->status = 0; 98 L->status = LUA_OK;
99 L->base_ci = L->ci = NULL; 99 L->base_ci = L->ci = NULL;
100 L->savedpc = NULL; 100 L->savedpc = NULL;
101 L->errfunc = 0; 101 L->errfunc = 0;
@@ -189,7 +189,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
189 g->gcstepmul = LUAI_GCMUL; 189 g->gcstepmul = LUAI_GCMUL;
190 g->gcdept = 0; 190 g->gcdept = 0;
191 for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL; 191 for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;
192 if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { 192 if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
193 /* memory allocation error: free partial state */ 193 /* memory allocation error: free partial state */
194 close_state(L); 194 close_state(L);
195 L = NULL; 195 L = NULL;
@@ -216,7 +216,7 @@ LUA_API void lua_close (lua_State *L) {
216 L->ci = L->base_ci; 216 L->ci = L->base_ci;
217 L->base = L->top = L->ci->base; 217 L->base = L->top = L->ci->base;
218 G(L)->nCcalls = 0; 218 G(L)->nCcalls = 0;
219 } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); 219 } while (luaD_rawrunprotected(L, callallgcTM, NULL) != LUA_OK);
220 lua_assert(G(L)->tmudata == NULL); 220 lua_assert(G(L)->tmudata == NULL);
221 luai_userstateclose(L); 221 luai_userstateclose(L);
222 close_state(L); 222 close_state(L);
diff --git a/ltests.c b/ltests.c
index 665b5d90..c2d88d2e 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.38 2006/07/11 15:53:29 roberto Exp roberto $ 2** $Id: ltests.c,v 2.39 2006/09/11 14:07:24 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -690,7 +690,7 @@ static int doonnewstack (lua_State *L) {
690 size_t l; 690 size_t l;
691 const char *s = luaL_checklstring(L, 1, &l); 691 const char *s = luaL_checklstring(L, 1, &l);
692 int status = luaL_loadbuffer(L1, s, l, s); 692 int status = luaL_loadbuffer(L1, s, l, s);
693 if (status == 0) 693 if (status == LUA_OK)
694 status = lua_pcall(L1, 0, 0, 0); 694 status = lua_pcall(L1, 0, 0, 0);
695 lua_pushinteger(L, status); 695 lua_pushinteger(L, status);
696 return 1; 696 return 1;
@@ -759,9 +759,9 @@ static int doremote (lua_State *L) {
759 int status; 759 int status;
760 lua_settop(L1, 0); 760 lua_settop(L1, 0);
761 status = luaL_loadbuffer(L1, code, lcode, code); 761 status = luaL_loadbuffer(L1, code, lcode, code);
762 if (status == 0) 762 if (status == LUA_OK)
763 status = lua_pcall(L1, 0, LUA_MULTRET, 0); 763 status = lua_pcall(L1, 0, LUA_MULTRET, 0);
764 if (status != 0) { 764 if (status != LUA_OK) {
765 lua_pushnil(L); 765 lua_pushnil(L);
766 lua_pushinteger(L, status); 766 lua_pushinteger(L, status);
767 lua_pushstring(L, lua_tostring(L1, -1)); 767 lua_pushstring(L, lua_tostring(L1, -1));
diff --git a/lua.c b/lua.c
index e0f56fc0..38419c14 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.162 2006/09/11 14:07:24 roberto Exp roberto $ 2** $Id: lua.c,v 1.163 2006/09/18 14:03:18 roberto Exp roberto $
3** Lua stand-alone interpreter 3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -63,7 +63,7 @@ static void l_message (const char *pname, const char *msg) {
63 63
64 64
65static int report (lua_State *L, int status) { 65static int report (lua_State *L, int status) {
66 if (status && !lua_isnil(L, -1)) { 66 if (status != LUA_OK && !lua_isnil(L, -1)) {
67 const char *msg = lua_tostring(L, -1); 67 const char *msg = lua_tostring(L, -1);
68 if (msg == NULL) msg = "(error object is not a string)"; 68 if (msg == NULL) msg = "(error object is not a string)";
69 l_message(progname, msg); 69 l_message(progname, msg);
@@ -101,7 +101,7 @@ static int docall (lua_State *L, int narg, int clear) {
101 signal(SIGINT, SIG_DFL); 101 signal(SIGINT, SIG_DFL);
102 lua_remove(L, base); /* remove traceback function */ 102 lua_remove(L, base); /* remove traceback function */
103 /* force a complete garbage collection in case of errors */ 103 /* force a complete garbage collection in case of errors */
104 if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0); 104 if (status != LUA_OK) lua_gc(L, LUA_GCCOLLECT, 0);
105 return status; 105 return status;
106} 106}
107 107
@@ -130,13 +130,15 @@ static int getargs (lua_State *L, char **argv, int n) {
130 130
131 131
132static int dofile (lua_State *L, const char *name) { 132static int dofile (lua_State *L, const char *name) {
133 int status = luaL_loadfile(L, name) || docall(L, 0, 1); 133 int status = luaL_loadfile(L, name);
134 if (status == LUA_OK) status = docall(L, 0, 1);
134 return report(L, status); 135 return report(L, status);
135} 136}
136 137
137 138
138static int dostring (lua_State *L, const char *s, const char *name) { 139static int dostring (lua_State *L, const char *s, const char *name) {
139 int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1); 140 int status = luaL_loadbuffer(L, s, strlen(s), name);
141 if (status == LUA_OK) status = docall(L, 0, 1);
140 return report(L, status); 142 return report(L, status);
141} 143}
142 144
@@ -218,12 +220,12 @@ static void dotty (lua_State *L) {
218 const char *oldprogname = progname; 220 const char *oldprogname = progname;
219 progname = NULL; 221 progname = NULL;
220 while ((status = loadline(L)) != -1) { 222 while ((status = loadline(L)) != -1) {
221 if (status == 0) status = docall(L, 0, 0); 223 if (status == LUA_OK) status = docall(L, 0, 0);
222 report(L, status); 224 report(L, status);
223 if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ 225 if (status == LUA_OK && lua_gettop(L) > 0) { /* any result to print? */
224 lua_getglobal(L, "print"); 226 lua_getglobal(L, "print");
225 lua_insert(L, 1); 227 lua_insert(L, 1);
226 if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0) 228 if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != LUA_OK)
227 l_message(progname, lua_pushfstring(L, 229 l_message(progname, lua_pushfstring(L,
228 "error calling " LUA_QL("print") " (%s)", 230 "error calling " LUA_QL("print") " (%s)",
229 lua_tostring(L, -1))); 231 lua_tostring(L, -1)));
@@ -246,7 +248,7 @@ static int handle_script (lua_State *L, char **argv, int n) {
246 fname = NULL; /* stdin */ 248 fname = NULL; /* stdin */
247 status = luaL_loadfile(L, fname); 249 status = luaL_loadfile(L, fname);
248 lua_insert(L, -(narg+1)); 250 lua_insert(L, -(narg+1));
249 if (status == 0) 251 if (status == LUA_OK)
250 status = docall(L, narg, 0); 252 status = docall(L, narg, 0);
251 else 253 else
252 lua_pop(L, narg); 254 lua_pop(L, narg);
@@ -301,28 +303,28 @@ static int runargs (lua_State *L, char **argv, int n) {
301 const char *chunk = argv[i] + 2; 303 const char *chunk = argv[i] + 2;
302 if (*chunk == '\0') chunk = argv[++i]; 304 if (*chunk == '\0') chunk = argv[++i];
303 lua_assert(chunk != NULL); 305 lua_assert(chunk != NULL);
304 if (dostring(L, chunk, "=(command line)") != 0) 306 if (dostring(L, chunk, "=(command line)") != LUA_OK)
305 return 1; 307 return 0;
306 break; 308 break;
307 } 309 }
308 case 'l': { 310 case 'l': {
309 const char *filename = argv[i] + 2; 311 const char *filename = argv[i] + 2;
310 if (*filename == '\0') filename = argv[++i]; 312 if (*filename == '\0') filename = argv[++i];
311 lua_assert(filename != NULL); 313 lua_assert(filename != NULL);
312 if (dolibrary(L, filename)) 314 if (dolibrary(L, filename) != LUA_OK)
313 return 1; /* stop if file fails */ 315 return 0; /* stop if file fails */
314 break; 316 break;
315 } 317 }
316 default: break; 318 default: break;
317 } 319 }
318 } 320 }
319 return 0; 321 return 1;
320} 322}
321 323
322 324
323static int handle_luainit (lua_State *L) { 325static int handle_luainit (lua_State *L) {
324 const char *init = getenv(LUA_INIT); 326 const char *init = getenv(LUA_INIT);
325 if (init == NULL) return 0; /* status OK */ 327 if (init == NULL) return LUA_OK;
326 else if (init[0] == '@') 328 else if (init[0] == '@')
327 return dofile(L, init+1); 329 return dofile(L, init+1);
328 else 330 else
@@ -333,7 +335,7 @@ static int handle_luainit (lua_State *L) {
333struct Smain { 335struct Smain {
334 int argc; 336 int argc;
335 char **argv; 337 char **argv;
336 int status; 338 int ok;
337}; 339};
338 340
339 341
@@ -347,20 +349,20 @@ static int pmain (lua_State *L) {
347 lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ 349 lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
348 luaL_openlibs(L); /* open libraries */ 350 luaL_openlibs(L); /* open libraries */
349 lua_gc(L, LUA_GCRESTART, 0); 351 lua_gc(L, LUA_GCRESTART, 0);
350 s->status = handle_luainit(L); 352 s->ok = (handle_luainit(L) == LUA_OK);
351 if (s->status != 0) return 0; 353 if (!s->ok) return 0;
352 script = collectargs(argv, &has_i, &has_v, &has_e); 354 script = collectargs(argv, &has_i, &has_v, &has_e);
353 if (script < 0) { /* invalid args? */ 355 if (script < 0) { /* invalid args? */
354 print_usage(); 356 print_usage();
355 s->status = 1; 357 s->ok = 0;
356 return 0; 358 return 0;
357 } 359 }
358 if (has_v) print_version(); 360 if (has_v) print_version();
359 s->status = runargs(L, argv, (script > 0) ? script : s->argc); 361 s->ok = runargs(L, argv, (script > 0) ? script : s->argc);
360 if (s->status != 0) return 0; 362 if (!s->ok) return 0;
361 if (script) 363 if (script)
362 s->status = handle_script(L, argv, script); 364 s->ok = (handle_script(L, argv, script) == LUA_OK);
363 if (s->status != 0) return 0; 365 if (!s->ok) return 0;
364 if (has_i) 366 if (has_i)
365 dotty(L); 367 dotty(L);
366 else if (script == 0 && !has_e && !has_v) { 368 else if (script == 0 && !has_e && !has_v) {
@@ -387,6 +389,6 @@ int main (int argc, char **argv) {
387 status = lua_cpcall(L, &pmain, &s); 389 status = lua_cpcall(L, &pmain, &s);
388 report(L, status); 390 report(L, status);
389 lua_close(L); 391 lua_close(L);
390 return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS; 392 return (s.ok && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
391} 393}
392 394
diff --git a/lua.h b/lua.h
index 7e698e36..960b9857 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.219 2006/09/11 14:07:24 roberto Exp roberto $ 2** $Id: lua.h,v 1.220 2006/09/18 14:03:18 roberto Exp roberto $
3** Lua - An Extensible Extension Language 3** Lua - An Extensible Extension Language
4** Lua.org, PUC-Rio, Brazil (http://www.lua.org) 4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
5** See Copyright Notice at the end of this file 5** See Copyright Notice at the end of this file
@@ -39,7 +39,8 @@
39#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) 39#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i))
40 40
41 41
42/* thread status; 0 is OK */ 42/* thread status */
43#define LUA_OK 0
43#define LUA_YIELD 1 44#define LUA_YIELD 1
44#define LUA_ERRRUN 2 45#define LUA_ERRRUN 2
45#define LUA_ERRSYNTAX 3 46#define LUA_ERRSYNTAX 3