Ellipsis not working?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
khamarr3524
Prole
Posts: 41
Joined: Thu Sep 05, 2013 8:48 pm

Ellipsis not working?

Post by khamarr3524 »

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

Code: Select all

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.
PGUp
Party member
Posts: 105
Joined: Fri Apr 21, 2017 9:17 am

Re: Ellipsis not working?

Post by PGUp »

Like this ?

Code: Select 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.
-
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Ellipsis not working?

Post by grump »

Code: Select all

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
khamarr3524
Prole
Posts: 41
Joined: Thu Sep 05, 2013 8:48 pm

Re: Ellipsis not working?

Post by khamarr3524 »

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.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Ellipsis not working?

Post by grump »

It's not hijacking anything. You keep confusing ellipsis and the global arg table. They're entirely different things.
khamarr3524
Prole
Posts: 41
Joined: Thu Sep 05, 2013 8:48 pm

Re: Ellipsis not working?

Post by khamarr3524 »

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.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Ellipsis not working?

Post by grump »

PIL is outdated in this regard. 5.1 changed how ellipsis and arg are used. See my first comment, that's how they work in Lua 5.1.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Ellipsis not working?

Post by zorg »

Also, table.getn is replaced by the # operator, and the module keyword is deprecated. :3

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 :3True 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.
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Ellipsis not working?

Post by pgimeno »

It's actually a difference between Lua and LuaJIT.

Lua 5.1 still recognizes arg, but LuaJIT doesn't. See http://luajit.org/faq.html (third item).

Code: Select all

$ 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
> 
khamarr3524
Prole
Posts: 41
Joined: Thu Sep 05, 2013 8:48 pm

Re: Ellipsis not working?

Post by khamarr3524 »

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
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 0 guests