View Single Post
01-18-14, 08:03 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Duugu View Post
I would do it like this:
Do not do it like that.

Instead, use the private table Blizzard provides each and every addon for exactly this purpose. This table is not in the global namespace (though you can put it there if you want) and you can access it by adding a line like this to each of your files:

Code:
local ADDON_NAME, addon_private_table = ...
You can use whatever variable names you want, you don't have to use the same names in each file, and you don't need to assign them at all in files where you don't need them, but you do need to assign them in the main chunk (top-level in the file, not in a function, not in a do...end block, etc.), and you should assign them at or near the top of the file.

The first value in the file-level vararg (the three dots) is a string containing your addon's name. It's the same value that's passed with your addon's ADDON_LOADED event, and that you can pass to GetAddOnInfo and similar functions.

The second value is a table. You can put whatever you want in it. It's only visible to the files in your addon, though you can make it global if you really want:

Code:
local ADDON, private = ...
_G[ADDON] = private
__________________
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