View Single Post
08-16-14, 09:00 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by SDPhantom View Post
This isn't restricted to just WoW. The entire file, known as the main chunk, is seen by Lua as a function. After compiling into its own binary format, Lua immediately runs the function generated.
To add to this, in WoW, the function receives two arguments. The first argument is a string containing the addon's folder/TOC name, and the second argument is a table. The same string and table are passed to each file within the same addon, so you can use the table to share data between your files without putting it in the global namespace. This is what's happening when you see things like this at the top of files:

Code:
local ADDON_NAME, private_table = ...
This line simply captures the variables passed into the file, and assigns them to whatever named variables the author prefers.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote