Page 1 of 1

Arg returns directory path and nothing else

Posted: Sun May 27, 2018 8:26 am
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)

Re: Arg returns directory path and nothing else

Posted: Sun May 27, 2018 8:31 am
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

Re: Arg returns directory path and nothing else

Posted: Sun May 27, 2018 8:35 am
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