seomoz / qless-core

Core Lua Scripts for qless
MIT License
85 stars 34 forks source link

Use vararg expression instead `arg` table. #70

Open moteus opened 7 years ago

moteus commented 7 years ago

vararg expression was introduced in Lua 5.1

The vararg system changed from the pseudo-argument `arg` with a table with the extra arguments to the vararg expression.

And since Lua 5.2 it does not avaliable. (At least without compt compile flags). Instead or this better use vararg expression like.

-- e.g. instead of
function f1(a, ...)  print(unpack(arg)) end
function f2(a, ...)  print(a, ...) end

If you need handle vararg as array you can do

function f1(...) 
  -- do not use `arg` name for this variable
  local argv, argc = {...}, select('#', ...)
  for i = 1, argc do
    -- handle argv[i]
  end