lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> 	- stand-alone interpreter creates 'arg' before running any code

Great to see this change. But... I noticed that the main code still gets the varargs '...' with the original arguments;

Consider a file 'cmdline.lua' with contents:

print("--- arg ---")
for k,v in pairs(arg) do print(k,v) end
print("--- vararg ---")
for k,v in pairs({...}) do print(k,v) end

And then execute;
C:\Temp\lua-5.3.0-work3\local\bin>lua -e "table.remove(arg,1)" -- cmdline.lua and some options
--- arg ---
1       some
2       options
0       cmdline.lua
-4      lua
-3      -e
-2      table.remove(arg,1)
-1      --
--- vararg ---
1       and
2       some
3       options

The 'arg' table dump properly shows that 'and' as parameter has been removed, but the `vararg` list still contains 'and'. So when debugging commandline scripts I can only 'fix' arguments for scripts that use the `arg` approach, but not scripts that use the `...` approach.

I think the main chunk should be called as;
  pcall(mainchunk, table.unpack(arg, 1, #arg))

to prevent this.