View Single Post
01-11-15, 11:26 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
The vararg (...) merely represents a variable number of arguments. The game client passes through two arguments to each Lua file in an addon. Think of it like the Lua file is contained in a function that executes it, and it looks like this:
Lua Code:
  1. function ExecuteFile(...)
  2.      --all Lua file contents, functions, etc, etc
  3. end
  4.  
  5. ExecuteFile()

That means that if you assign the vararg to variables in your file in the main scope (outside of any functions or other blocks of code, usually done at the top of your file) then you can have access to what Blizzard is passing through to your file.

The two arguments are 1. the name of your addon, and 2. a table that is local to all files in your addon's folder. Think of this table as being a hybrid of a global and a local. It's global in that you can access it across all your files, but it's local in that nothing outside of your addon knows about it. So now, imagine that the game is doing this:
Lua Code:
  1. local addonName, addonTable = "Name of Addon", {}
  2.  
  3. function ExecuteFile1(addonName, addonTable)
  4.      --your file contents
  5. end
  6.  
  7. function ExecuteFile2(addonName, addonTable)
  8.      --this file's contents
  9. end
  10.  
  11. ExecuteFile1()
  12. ExecuteFile2()

So, at the top of each of your Lua files, put this line (note, you can use whatever variable names you want, and they can even be called different things in each file - they'll still reference the same things):
Lua Code:
  1. local addonName, addonTable = ...

Now, anything stored in the addonTable table can be accessed in each file, and the table may be added to, etc. from each file.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote