Originally Posted by SDPhantom
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.