Shejo284
Shejo284

Reputation: 4761

Workaround for error: "outside a vararg function near"

While refractoring some lua (v5.3) code I didn't write, I came across an error for which I cannot find a good explanation/work-around. The error has to do with vararg (...).

local function A()
   args = getargs(...)
   ... some more code
end

A()

I cannot paste the real code here since it will not work, but I hope you can see the problem from the example above: when I encapsulated args = getargs(...) inside A() I get the error:

cannot use '...' outside a vararg function near '...' I'm new to LUA but not new to programming so I find this error a bit strange. If args and getargs() are global, why am I getting this error and how do I get around it? The solution is not further nesting of getargs().

Upvotes: 2

Views: 1828

Answers (1)

val - disappointed in SE
val - disappointed in SE

Reputation: 1543

Your real problem is that A() isn't vararg itself. This code shoul fix it:

local function A(...) -- Now this is vararg
   args = getargs(...)
   ... some more code
end

A()

P.S. why not make args local? Having both arg and args is confusing!

Upvotes: 2

Related Questions