4

I have a problem in use implicit parameter arg in functions.

The code not works. The documentation, http://www.lua.org/pil/5.2.html, should works.

function listar_um (...)
  for i,v in ipairs(arg) do
    print("usando args " .. arg[i])  
  end
end
listar_um("Olá", 1, "Dois")

This code works with the declaring variable lista.

function listar_um (...)
  lista = {...}

  for i,v in ipairs(lista) do
    print("não usando args " .. lista[i])  
  end
end
listar_um("Olá", 1, "Dois")

Why the first example does not work?

Script for test: http://www.codeshare.io/IPwRJ Execute on-line script: http://www.compileonline.com/execute_lua_online.php

Thanks.

1 Answer 1

4

The first edition of PiL talks about Lua 5.0. The use of arg is available in Lua 5.0, while it's removed since Lua 5.1

You can find it in Lua 5.0 reference manual, but not in Lua 5.1 reference manual.

The edition the online interpreter uses is Lua 5.2, you can find out by print(_VERSION).


Edit: after some tests, it seems that arg is still available in Lua 5.1, but not working in Lua 5.2.

Sign up to request clarification or add additional context in comments.

1 Comment

arg still exists in the main Lua 5.1 implementation for backwards compatibility. It's definitely not in LuaJIT though, and possibly not in other implementations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.