aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-08-27 14:55:35 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-08-27 14:55:35 -0300
commit9ac9d23f4164fc7e1eeea8a3e8d4e453dade51ab (patch)
treea2283e372f1ef05bdba8d9d41787ad872d09ce6e
parent1b0f943da7dfb25987456a77259edbeea0b94edc (diff)
downloadlua-9ac9d23f4164fc7e1eeea8a3e8d4e453dade51ab.tar.gz
lua-9ac9d23f4164fc7e1eeea8a3e8d4e453dade51ab.tar.bz2
lua-9ac9d23f4164fc7e1eeea8a3e8d4e453dade51ab.zip
Bug: error with option '--' without a script
-rw-r--r--lua.c3
-rw-r--r--testes/main.lua10
2 files changed, 8 insertions, 5 deletions
diff --git a/lua.c b/lua.c
index 4a90e55d..8055b70f 100644
--- a/lua.c
+++ b/lua.c
@@ -302,7 +302,8 @@ static int collectargs (char **argv, int *first) {
302 case '-': /* '--' */ 302 case '-': /* '--' */
303 if (argv[i][2] != '\0') /* extra characters after '--'? */ 303 if (argv[i][2] != '\0') /* extra characters after '--'? */
304 return has_error; /* invalid option */ 304 return has_error; /* invalid option */
305 *first = i + 1; 305 /* if there is a script name, it comes after '--' */
306 *first = (argv[i + 1] != NULL) ? i + 1 : 0;
306 return args; 307 return args;
307 case '\0': /* '-' */ 308 case '\0': /* '-' */
308 return args; /* script "name" is '-' */ 309 return args; /* script "name" is '-' */
diff --git a/testes/main.lua b/testes/main.lua
index cec4fa04..ff408f13 100644
--- a/testes/main.lua
+++ b/testes/main.lua
@@ -90,7 +90,7 @@ prepfile[[
901, a 901, a
91) 91)
92]] 92]]
93RUN('lua - < %s > %s', prog, out) 93RUN('lua - -- < %s > %s', prog, out)
94checkout("1\tnil\n") 94checkout("1\tnil\n")
95 95
96RUN('echo "print(10)\nprint(2)\n" | lua > %s', out) 96RUN('echo "print(10)\nprint(2)\n" | lua > %s', out)
@@ -133,7 +133,7 @@ checkout("-h\n")
133prepfile("print(package.path)") 133prepfile("print(package.path)")
134 134
135-- test LUA_PATH 135-- test LUA_PATH
136RUN('env LUA_INIT= LUA_PATH=x lua %s > %s', prog, out) 136RUN('env LUA_INIT= LUA_PATH=x lua -- %s > %s', prog, out)
137checkout("x\n") 137checkout("x\n")
138 138
139-- test LUA_PATH_version 139-- test LUA_PATH_version
@@ -346,7 +346,7 @@ RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out)
346checkprogout("6\n10\n10\n\n") 346checkprogout("6\n10\n10\n\n")
347 347
348prepfile("a = [[b\nc\nd\ne]]\n=a") 348prepfile("a = [[b\nc\nd\ne]]\n=a")
349RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out) 349RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i -- < %s > %s]], prog, out)
350checkprogout("b\nc\nd\ne\n\n") 350checkprogout("b\nc\nd\ne\n\n")
351 351
352-- input interrupted in continuation line 352-- input interrupted in continuation line
@@ -478,12 +478,14 @@ assert(not os.remove(out))
478-- invalid options 478-- invalid options
479NoRun("unrecognized option '-h'", "lua -h") 479NoRun("unrecognized option '-h'", "lua -h")
480NoRun("unrecognized option '---'", "lua ---") 480NoRun("unrecognized option '---'", "lua ---")
481NoRun("unrecognized option '-Ex'", "lua -Ex") 481NoRun("unrecognized option '-Ex'", "lua -Ex --")
482NoRun("unrecognized option '-vv'", "lua -vv") 482NoRun("unrecognized option '-vv'", "lua -vv")
483NoRun("unrecognized option '-iv'", "lua -iv") 483NoRun("unrecognized option '-iv'", "lua -iv")
484NoRun("'-e' needs argument", "lua -e") 484NoRun("'-e' needs argument", "lua -e")
485NoRun("syntax error", "lua -e a") 485NoRun("syntax error", "lua -e a")
486NoRun("'-l' needs argument", "lua -l") 486NoRun("'-l' needs argument", "lua -l")
487NoRun("-i", "lua -- -i") -- handles -i as a script name
488
487 489
488 490
489if T then -- test library? 491if T then -- test library?