Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use vararg expression instead arg table. #70

Open
moteus opened this issue Mar 3, 2017 · 0 comments
Open

Use vararg expression instead arg table. #70

moteus opened this issue Mar 3, 2017 · 0 comments

Comments

@moteus
Copy link
Contributor

moteus commented Mar 3, 2017

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant