diff options
Diffstat (limited to 'lua.c')
| -rw-r--r-- | lua.c | 17 |
1 files changed, 10 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.48 2000/08/31 14:28:17 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.49 2000/08/31 20:23:40 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 | */ |
| @@ -54,6 +54,7 @@ extern void USERINIT (void); | |||
| 54 | #else | 54 | #else |
| 55 | #define USERINIT userinit | 55 | #define USERINIT userinit |
| 56 | static void userinit (void) { | 56 | static void userinit (void) { |
| 57 | lua_baselibopen(L); | ||
| 57 | lua_iolibopen(L); | 58 | lua_iolibopen(L); |
| 58 | lua_strlibopen(L); | 59 | lua_strlibopen(L); |
| 59 | lua_mathlibopen(L); | 60 | lua_mathlibopen(L); |
| @@ -103,7 +104,7 @@ static void print_message (void) { | |||
| 103 | fprintf(stderr, | 104 | fprintf(stderr, |
| 104 | "usage: lua [options]. Available options are:\n" | 105 | "usage: lua [options]. Available options are:\n" |
| 105 | " - execute stdin as a file\n" | 106 | " - execute stdin as a file\n" |
| 106 | " -c close lua when exiting\n" | 107 | " -c close Lua when exiting\n" |
| 107 | " -e stat execute string `stat'\n" | 108 | " -e stat execute string `stat'\n" |
| 108 | " -f name execute file `name' with remaining arguments in table `arg'\n" | 109 | " -f name execute file `name' with remaining arguments in table `arg'\n" |
| 109 | " -i enter interactive mode with prompt\n" | 110 | " -i enter interactive mode with prompt\n" |
| @@ -134,12 +135,14 @@ static void getargs (char *argv[]) { | |||
| 134 | lua_newtable(L); | 135 | lua_newtable(L); |
| 135 | for (i=0; argv[i]; i++) { | 136 | for (i=0; argv[i]; i++) { |
| 136 | /* arg[i] = argv[i] */ | 137 | /* arg[i] = argv[i] */ |
| 137 | lua_pushobject(L, -1); lua_pushnumber(L, i); | 138 | lua_pushnumber(L, i); |
| 138 | lua_pushstring(L, argv[i]); lua_settable(L); | 139 | lua_pushstring(L, argv[i]); |
| 140 | lua_settable(L, -3); | ||
| 139 | } | 141 | } |
| 140 | /* arg.n = maximum index in table `arg' */ | 142 | /* arg.n = maximum index in table `arg' */ |
| 141 | lua_pushobject(L, -1); lua_pushstring(L, "n"); | 143 | lua_pushstring(L, "n"); |
| 142 | lua_pushnumber(L, i-1); lua_settable(L); | 144 | lua_pushnumber(L, i-1); |
| 145 | lua_settable(L, -3); | ||
| 143 | } | 146 | } |
| 144 | 147 | ||
| 145 | 148 | ||
| @@ -311,7 +314,7 @@ int main (int argc, char *argv[]) { | |||
| 311 | int status; | 314 | int status; |
| 312 | opt.toclose = 0; | 315 | opt.toclose = 0; |
| 313 | getstacksize(argc, argv, &opt); /* handle option `-s' */ | 316 | getstacksize(argc, argv, &opt); /* handle option `-s' */ |
| 314 | L = lua_newstate(opt.stacksize, 1); /* create state */ | 317 | L = lua_newstate(opt.stacksize); /* create state */ |
| 315 | USERINIT(); /* open libraries */ | 318 | USERINIT(); /* open libraries */ |
| 316 | register_getargs(argv); /* create `getargs' function */ | 319 | register_getargs(argv); /* create `getargs' function */ |
| 317 | status = handle_argv(argv+1, &opt); | 320 | status = handle_argv(argv+1, &opt); |
