diff --git a/lua.c b/lua.c index b725944e..cc698d0b 100644 --- a/lua.c +++ b/lua.c @@ -1,5 +1,5 @@ /* -** $Id: lua.c,v 1.28 1999/12/06 11:41:28 roberto Exp roberto $ +** $Id: lua.c,v 1.29 1999/12/20 13:03:20 roberto Exp roberto $ ** Lua stand-alone interpreter ** See Copyright Notice in lua.h */ @@ -74,7 +74,7 @@ static void print_message (void) { " -q interactive mode without prompt\n" " -i interactive mode with prompt\n" " - execute stdin as a file\n" -" -- start arguments for table `arg'\n" +" -f name dofile `name' with following arguments in table `arg'\n" " a=b set global `a' with string `b'\n" " name dofile `name'\n\n"); } @@ -96,27 +96,34 @@ static void assign (char *arg) { static void getargs (int argc, char *argv[]) { lua_beginblock(); { - int i, j; + int i; lua_Object args = lua_createtable(); lua_pushobject(args); lua_setglobal("arg"); - for (i=0; i=argc) { + print_message(); + exit(1); + } if (ldo(lua_dostring, argv[i]) != 0) { fprintf(stderr, "lua: error running argument `%s'\n", argv[i]); - return 1; + exit(1); } break; + case 'f': + i++; + if (i>=argc) { + print_message(); + exit(1); + } + getargs(argc-i, argv+i); /* collect following arguments */ + file_input(argv, i); + return 0; /* stop running arguments */ case '-': i = argc; /* end loop */ break; @@ -202,16 +221,8 @@ int main (int argc, char *argv[]) { } else if (strchr(argv[i], '=')) assign(argv[i]); - else { - int result = ldo(lua_dofile, argv[i]); - if (result) { - if (result == 2) { - fprintf(stderr, "lua: cannot execute file "); - perror(argv[i]); - } - exit(1); - } - } + else + file_input(argv, i); } #ifdef DEBUG lua_close();