History

Lua 5.1-rc1

Lua Team committed 20 years ago

Commit 53d3c321 parent 27f2ec746 files · +1822 −1531Browse files

Showing the changes to src/lua.c (1 of 46 files). Show all

Unified · Split

src/lua.c+9−5
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lua.c,v 1.154 2005/10/24 17:38:47 roberto Exp $2** $Id: lua.c,v 1.157 2005/12/29 16:23:32 roberto Exp $
3** Lua stand-alone interpreter3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -120,7 +120,7 @@ static int getargs (lua_State *L, char **argv, int n) { · 114 unmodified lines
120 luaL_checkstack(L, narg + 3, "too many arguments to script");120 luaL_checkstack(L, narg + 3, "too many arguments to script");
121 for (i=n+1; i < argc; i++)121 for (i=n+1; i < argc; i++)
122 lua_pushstring(L, argv[i]);122 lua_pushstring(L, argv[i]);
123 lua_newtable(L);123 lua_createtable(L, narg, n + 1);
124 for (i=0; i < argc; i++) {124 for (i=0; i < argc; i++) {
125 lua_pushstring(L, argv[i]);125 lua_pushstring(L, argv[i]);
126 lua_rawseti(L, -2, i - n);126 lua_rawseti(L, -2, i - n);
@@ -215,7 +215,6 @@ static void dotty (lua_State *L) { · 88 unmodified lines
215 int status;215 int status;
216 const char *oldprogname = progname;216 const char *oldprogname = progname;
217 progname = NULL;217 progname = NULL;
218 print_version();
219 while ((status = loadline(L)) != -1) {218 while ((status = loadline(L)) != -1) {
220 if (status == 0) status = docall(L, 0, 0);219 if (status == 0) status = docall(L, 0, 0);
221 report(L, status);220 report(L, status);
@@ -261,7 +260,7 @@ static int collectargs (char **argv, int *pi, int *pv, int *pe) { · 39 unmodified lines
261 switch (argv[i][1]) { /* option */260 switch (argv[i][1]) { /* option */
262 case '-': return (argv[i+1] != NULL ? i+1 : 0);261 case '-': return (argv[i+1] != NULL ? i+1 : 0);
263 case '\0': return i;262 case '\0': return i;
264 case 'i': *pi = 1; break;263 case 'i': *pi = 1; /* go through */
265 case 'v': *pv = 1; break;264 case 'v': *pv = 1; break;
266 case 'e': *pe = 1; /* go through */265 case 'e': *pe = 1; /* go through */
267 case 'l':266 case 'l':
@@ -330,7 +329,9 @@ static int pmain (lua_State *L) { · 62 unmodified lines
330 int has_i = 0, has_v = 0, has_e = 0;329 int has_i = 0, has_v = 0, has_e = 0;
331 globalL = L;330 globalL = L;
332 if (argv[0] && argv[0][0]) progname = argv[0];331 if (argv[0] && argv[0][0]) progname = argv[0];
332 lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
333 luaL_openlibs(L); /* open libraries */333 luaL_openlibs(L); /* open libraries */
334 lua_gc(L, LUA_GCRESTART, 0);
334 s->status = handle_luainit(L);335 s->status = handle_luainit(L);
335 if (s->status != 0) return 0;336 if (s->status != 0) return 0;
336 script = collectargs(argv, &has_i, &has_v, &has_e);337 script = collectargs(argv, &has_i, &has_v, &has_e);
@@ -348,7 +349,10 @@ static int pmain (lua_State *L) { · 11 unmodified lines
348 if (has_i)349 if (has_i)
349 dotty(L);350 dotty(L);
350 else if (script == 0 && !has_e && !has_v) {351 else if (script == 0 && !has_e && !has_v) {
351 if (lua_stdin_is_tty()) dotty(L);352 if (lua_stdin_is_tty()) {
353 print_version();
354 dotty(L);
355 }
352 else dofile(L, NULL); /* executes stdin as a file */356 else dofile(L, NULL); /* executes stdin as a file */
353 }357 }
354 return 0;358 return 0;