Arg returns directory path and nothing else

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
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Arg returns directory path and nothing else

Post by MadByte »

Hey. Maybe it's just to early in the morning for me right now but for some reason I can't get behind it:

Code: Select all

-- Conf.lua
function love.conf(t)
	t.console = true
end

-- main.lua
local function foo(...)
	for _,v in ipairs(arg) do
		print(v)
	end
end

foo("Hello", "you", 1, 2, 3)
-- Output: C:\Users\Lars\Desktop/Test
Why is the output the directory path instead of the passed variables in the foo function arguments? :monocle:
Thanks for the help. (LÖVE 11.1, Atom Editor, Win10).
(I feel so stupid)
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Arg returns directory path and nothing else

Post by zorg »

The answer lies in the fact that the vararg expression is not accessed through a variable called arg anymore (since lua 5.1+, but even that didn't really support that), and arg in löve is a global in the main thread having the command line arguments in it.

You want to either use {...} or the select statement if you want to work with varargs.

one reference i googled just now: https://stackoverflow.com/questions/482 ... g-variable
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
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Arg returns directory path and nothing else

Post by MadByte »

Thanks, easiest answer you ever had to give I guess.
I didn't used it for quite some time and I can remember that this worked in the past. "Arg" is also used in the Lua PIL that is linked
in my bookmarks, maybe I should update the link.
I go back to bed! n8
Post Reply

Who is online

Users browsing this forum: No registered users and 48 guests