Page 1 of 1

Command line switches

Posted: Mon Mar 24, 2014 1:22 am
by CorruptionEX
Hello again, I have a question regarding love.load and its only argument.

I found in the default love.run function, love.load is called with 'arg', which seems to be a table containing all the switches passed in when a game is started. I was able to find out that much on my own, but I was wondering a few other details so that i can use them in a completed game.

For instance: The switches are divided into positive and negative indexes. Negative indexes are switches I did not pass in, but rather the ones love is passing into itself. The two that keep appearing are '-1 embedded boot.lua' and '-2 bin\CLF.exe' which is the directory of my fused game. I was wondering what might be the purpose of these two, and will any more negative indexes appear under special circumstances.

Another questions is the consistency of the order of switches. If I start my games as such:

Code: Select all

 bin\CLF.exe -nonetwork -debug -width 1280 -height 720
I get a table like this:

Code: Select all

arg = {
  [-2] = "bin\CLF.exe"
  [-1] = "embedded boot.lua"
  [1] = "-nonetwork"
  [2] = "-debug"
  [3] = "-width"
  [4] = "1280"
  [5] = "-height"
  [6] = "720"
}
My question is, will all the switches I pass in always be in the correct order? In my example, switch #4 is an argument for the function specified by the 3rd switch (-width), and the same with switch 5 and 6. However, I could not find any documentation on this topic, and so theoretically, could the wrong switch could get the wrong data in front of it?

Both questions aren't of the highest importance, because i can do with out this functionality, but I am rather curious because I cant find a page on the love wiki or anywhere else describing the behavior of the 'arg' table that is passed in, and it would be nice if i could use them. If anyone can tell me how it all works, or point me to the right location, i would really appreciate it. I don't want to use it in my games if im not sure how they work entirely.

Re: Command line switches

Posted: Mon Mar 24, 2014 7:38 am
by bartbes
The arg table represents all visible and hidden arguments, which might also contain the love binary and the .love file. That said, it's always described in such a way that arg[1] is the first passed-in argument. They are also in order, simply because that's the only thing that makes sense.

Re: Command line switches

Posted: Wed Mar 26, 2014 9:57 am
by CorruptionEX
Thank you, however, I am still curious about the 'embedded boot.lua' switch. What is that there for?

Re: Command line switches

Posted: Wed Mar 26, 2014 1:51 pm
by tio
CorruptionEX wrote:Thank you, however, I am still curious about the 'embedded boot.lua' switch. What is that there for?
It's used for some initializations. You can see the code here.