diff options
| -rw-r--r-- | lua.c | 27 |
1 files changed, 11 insertions, 16 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.113 2002/12/04 17:38:31 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.114 2003/01/17 15:27:28 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 | */ |
| @@ -43,6 +43,9 @@ static int isatty (int x) { return x==0; } /* assume stdin is a tty */ | |||
| 43 | #define PROMPT2 ">> " | 43 | #define PROMPT2 ">> " |
| 44 | #endif | 44 | #endif |
| 45 | 45 | ||
| 46 | #ifndef PROGNAME | ||
| 47 | #define PROGNAME "lua" | ||
| 48 | #endif | ||
| 46 | 49 | ||
| 47 | #ifndef lua_userinit | 50 | #ifndef lua_userinit |
| 48 | #define lua_userinit(L) openstdlibs(L) | 51 | #define lua_userinit(L) openstdlibs(L) |
| @@ -56,7 +59,7 @@ static int isatty (int x) { return x==0; } /* assume stdin is a tty */ | |||
| 56 | 59 | ||
| 57 | static lua_State *L = NULL; | 60 | static lua_State *L = NULL; |
| 58 | 61 | ||
| 59 | static const char *progname; | 62 | static const char *progname = PROGNAME; |
| 60 | 63 | ||
| 61 | 64 | ||
| 62 | 65 | ||
| @@ -134,13 +137,6 @@ static int lcall (int narg, int clear) { | |||
| 134 | } | 137 | } |
| 135 | 138 | ||
| 136 | 139 | ||
| 137 | static int l_panic (lua_State *l) { | ||
| 138 | (void)l; | ||
| 139 | l_message(progname, "unable to recover; exiting"); | ||
| 140 | return 0; | ||
| 141 | } | ||
| 142 | |||
| 143 | |||
| 144 | static void print_version (void) { | 140 | static void print_version (void) { |
| 145 | l_message(NULL, LUA_VERSION " " LUA_COPYRIGHT); | 141 | l_message(NULL, LUA_VERSION " " LUA_COPYRIGHT); |
| 146 | } | 142 | } |
| @@ -329,10 +325,10 @@ static int handle_argv (char *argv[], int *interactive) { | |||
| 329 | if (*chunk == '\0') chunk = argv[++i]; | 325 | if (*chunk == '\0') chunk = argv[++i]; |
| 330 | if (chunk == NULL) { | 326 | if (chunk == NULL) { |
| 331 | print_usage(); | 327 | print_usage(); |
| 332 | return EXIT_FAILURE; | 328 | return 1; |
| 333 | } | 329 | } |
| 334 | if (dostring(chunk, "=<command line>") != 0) | 330 | if (dostring(chunk, "=<command line>") != 0) |
| 335 | return EXIT_FAILURE; | 331 | return 1; |
| 336 | break; | 332 | break; |
| 337 | } | 333 | } |
| 338 | case 'l': { | 334 | case 'l': { |
| @@ -340,10 +336,10 @@ static int handle_argv (char *argv[], int *interactive) { | |||
| 340 | if (*filename == '\0') filename = argv[++i]; | 336 | if (*filename == '\0') filename = argv[++i]; |
| 341 | if (filename == NULL) { | 337 | if (filename == NULL) { |
| 342 | print_usage(); | 338 | print_usage(); |
| 343 | return EXIT_FAILURE; | 339 | return 1; |
| 344 | } | 340 | } |
| 345 | if (load_file(filename)) | 341 | if (load_file(filename)) |
| 346 | return EXIT_FAILURE; /* stop if file fails */ | 342 | return 1; /* stop if file fails */ |
| 347 | break; | 343 | break; |
| 348 | } | 344 | } |
| 349 | case 'c': { | 345 | case 'c': { |
| @@ -356,7 +352,7 @@ static int handle_argv (char *argv[], int *interactive) { | |||
| 356 | } | 352 | } |
| 357 | default: { | 353 | default: { |
| 358 | print_usage(); | 354 | print_usage(); |
| 359 | return EXIT_FAILURE; | 355 | return 1; |
| 360 | } | 356 | } |
| 361 | } | 357 | } |
| 362 | } endloop: | 358 | } endloop: |
| @@ -401,7 +397,7 @@ static int pmain (lua_State *l) { | |||
| 401 | struct Smain *s = (struct Smain *)lua_touserdata(l, 1); | 397 | struct Smain *s = (struct Smain *)lua_touserdata(l, 1); |
| 402 | int status; | 398 | int status; |
| 403 | int interactive = 0; | 399 | int interactive = 0; |
| 404 | progname = s->argv[0]; | 400 | if (s->argv[0][0] != '\0') progname = s->argv[0]; |
| 405 | L = l; | 401 | L = l; |
| 406 | lua_userinit(l); /* open libraries */ | 402 | lua_userinit(l); /* open libraries */ |
| 407 | status = handle_luainit(); | 403 | status = handle_luainit(); |
| @@ -424,7 +420,6 @@ int main (int argc, char *argv[]) { | |||
| 424 | } | 420 | } |
| 425 | s.argc = argc; | 421 | s.argc = argc; |
| 426 | s.argv = argv; | 422 | s.argv = argv; |
| 427 | lua_atpanic(l, l_panic); | ||
| 428 | status = lua_cpcall(l, &pmain, &s); | 423 | status = lua_cpcall(l, &pmain, &s); |
| 429 | report(status); | 424 | report(status); |
| 430 | lua_close(l); | 425 | lua_close(l); |
