diff options
-rw-r--r-- | lua.c | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.173 2009/06/18 18:59:58 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.174 2009/07/15 17:35:20 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 | */ |
@@ -75,6 +75,18 @@ static int report (lua_State *L, int status) { | |||
75 | } | 75 | } |
76 | 76 | ||
77 | 77 | ||
78 | /* the next function is called unprotected, so it must avoid errors */ | ||
79 | static void finalreport (lua_State *L, int status) { | ||
80 | if (status != LUA_OK) { | ||
81 | const char *msg = (lua_type(L, -1) == LUA_TSTRING) ? lua_tostring(L, -1) | ||
82 | : NULL; | ||
83 | if (msg == NULL) msg = "(error object is not a string)"; | ||
84 | l_message(progname, msg); | ||
85 | lua_pop(L, 1); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | |||
78 | static int traceback (lua_State *L) { | 90 | static int traceback (lua_State *L) { |
79 | const char *msg = lua_tostring(L, 1); | 91 | const char *msg = lua_tostring(L, 1); |
80 | if (msg) | 92 | if (msg) |
@@ -383,7 +395,7 @@ int main (int argc, char **argv) { | |||
383 | s.argc = argc; | 395 | s.argc = argc; |
384 | s.argv = argv; | 396 | s.argv = argv; |
385 | status = lua_cpcall(L, &pmain, &s); | 397 | status = lua_cpcall(L, &pmain, &s); |
386 | report(L, status); | 398 | finalreport(L, status); |
387 | lua_close(L); | 399 | lua_close(L); |
388 | return (s.ok && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE; | 400 | return (s.ok && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE; |
389 | } | 401 | } |