So, couldn't find anything (not counting the shape) besides a post from 2009 on the use of ellipsis (...) in Love2D. For some reason, when I invoke an ellipsis it doesn't pass the args I gave it, it's passing the args called when love is run, I.E the project directory and the -debug flag (I'm using ZeroBrane). I tried building it as a .love file and it is still giving the same results. Is this something in my code that's causing ellipsis to not function correctly, or is this an issue with Love?
Edit: Can confirm this is happening in a fresh project as well. The following code gives the same issue
function aFunction(...)
print(arg[1] .. arg[2])
end
function love.load(dir, flags)
aFunction("Foo", "Bar", "123")
end
Edit2: This does seem to be an issue with love, if i add arg = {} to love.load it causes the arg table to be empty and invoking another function using ellipsis does not work at all.
function aFunction(...)
local arg = {...}
love.graphics.print(arg[1] .. arg[2] .. arg[3])
end
function love.draw(dir, flags)
aFunction("Foo", "Bar", "123")
end
Last edited by PGUp on Fri Feb 23, 2018 6:55 am, edited 1 time in total.
print(...) -- top level, outside functions: contains the current module name
function foo(...)
print(...) -- function level: vararg expression, contains (extra) arguments passed to function
end
print(unpack(arg)) -- global table arg: contains command line arguments
That's a workaround that will work, but there is still an underlying cause as to why Love is hijacking the ellipsis that would be interesting to find out what's causing it.
Unless there was a change (which is quite likely) from Lua 5.0 to 5.2 concerning ellipsis, lua default populates the global arg table with ellipsis, as seen here. Although it would make sense if Love2d is intentionally using the global arg table to retain the .exe args which is what you are saying.
Also, table.getn is replaced by the # operator, and the module keyword is deprecated.
And löve does use luaJIT by default, which is a combination of 5.1 plus some additional 5.2 stuff that doesn't interfere with how 5.1 did things.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
$ lua
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> function x(...) for k,v in next,arg do print(k,v) end end; x(1,2,3)
1 1
2 2
3 3
n 3
>
$ luajit
LuaJIT 2.0.4 -- Copyright (C) 2005-2015 Mike Pall. http://luajit.org/
JIT: ON CMOV SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc sink fuse
> function x(...) for k,v in next,arg do print(k,v) end end; x(1,2,3)
stdin:1: bad argument #1 to '(for generator)' (table expected, got nil)
stack traceback:
[C]: in function '(for generator)'
stdin:1: in function 'x'
stdin:1: in main chunk
[C]: at 0x557ebb8d16c0
> =arg
nil
>
That makes sense. I think I'm going to move away from ellipsis for a different reason, but at least I know now how if I want to do it I can. Thanks for the clarification @pgimeno