History

Lua 5.3.0-alpha

Lua Team committed 12 years ago

Commit ff8c9ca1 parent f8a662741 files · +1212 −882Browse files

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

Unified · Split

src/lua.c+18−12
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.c,v 1.211 2014/06/05 20:42:06 roberto Exp $
2+** $Id: lua.c,v 1.213 2014/06/30 19:48:08 roberto Exp $
33 ** Lua stand-alone interpreter
44 ** See Copyright Notice in lua.h
55 */
@@ -115,7 +115,7 @@ static void lstop (lua_State *L, lua_Debug *ar) { · 109 unmodified lines
115115
116116 /*
117117 ** Function to be called at a C signal. Because a C signal cannot
118−** just change a Lua state (as there is no proper syncronization),
118+** just change a Lua state (as there is no proper synchronization),
119119 ** this function only sets a hook that, when called, will stop the
120120 ** interpreter.
121121 */
@@ -284,7 +284,7 @@ static const char *get_prompt (lua_State *L, int firstline) { · 162 unmodified lines
284284 /*
285285 ** Check whether 'status' signals a syntax error and the error
286286 ** message at the top of the stack ends with the above mark for
287−** incoplete statements.
287+** incomplete statements.
288288 */
289289 static int incomplete (lua_State *L, int status) {
290290 if (status == LUA_ERRSYNTAX) {
@@ -417,25 +417,31 @@ static void doREPL (lua_State *L) { · 126 unmodified lines
417417
418418
419419 /*
420−** Push on the stack 'n' strings from 'argv'
420+** Push on the stack the contents of table 'arg' from 1 to #arg
421421 */
422−static void pushargs (lua_State *L, char **argv, int n) {
423− int i;
422+static int pushargs (lua_State *L) {
423+ int i, n;
424+ lua_getglobal(L, "arg");
425+ if (!lua_istable(L, -1))
426+ luaL_error(L, "'arg' is not a table");
427+ n = (int)luaL_len(L, -1);
424428 luaL_checkstack(L, n + 3, "too many arguments to script");
425− for (i = 1; i < n; i++) /* skip 0 (the script name) */
426− lua_pushstring(L, argv[i]);
429+ for (i = 1; i <= n; i++)
430+ lua_rawgeti(L, -i, i);
431+ lua_remove(L, -i); /* remove table from the stack */
432+ return n;
427433 }
428434
429435
430−static int handle_script (lua_State *L, char **argv, int n) {
436+static int handle_script (lua_State *L, char **argv) {
431437 int status;
432438 const char *fname = argv[0];
433439 if (strcmp(fname, "-") == 0 && strcmp(argv[-1], "--") != 0)
434440 fname = NULL; /* stdin */
435441 status = luaL_loadfile(L, fname);
436442 if (status == LUA_OK) {
437− pushargs(L, argv, n); /* push arguments to script */
438− status = docall(L, n - 1, LUA_MULTRET);
443+ int n = pushargs(L); /* push arguments to script */
444+ status = docall(L, n, LUA_MULTRET);
439445 }
440446 return report(L, status);
441447 }
@@ -570,7 +576,7 @@ static int pmain (lua_State *L) { · 128 unmodified lines
570576 if (!runargs(L, argv, script)) /* execute arguments -e and -l */
571577 return 0; /* something failed */
572578 if (script < argc && /* execute main script (if there is one) */
573− handle_script(L, argv + script, argc - script) != LUA_OK)
579+ handle_script(L, argv + script) != LUA_OK)
574580 return 0;
575581 if (args & has_i) /* -i option? */
576582 doREPL(L); /* do read-eval-print loop */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t