View Single Post
11-08-12, 03:50 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Aanson View Post
Lua Code:
  1. local addon, addonName = ...
  2.  
  3. core[1] = {};
  4. core[2] = {};
  5.  
  6. local F, V = unpack(select(2, ...));
I'm not really sure where you are going (or trying to go) with that code, and it should be dying with nil value errors because you're attempting to add values to a core table you never defined as a table (or anything else).

Also, the vararg passed to addon Lua files gives the addon's name first, and the private table second, so your order is backwards:

Code:
local addonName, addonPrivateTable = ...
Also also, since you already have a reference to the private table, there's no need to spend a select call to get it again:

Code:
local F, V = unpack(addonPrivateTable)
Originally Posted by Aanson View Post
how bad would it be for the Chat_Module.lua functions to be read and stored to memory, but never called?
Not bad at all. Even if your chat module is 100 KB of code, who cares? The static memory usage of a WoW addon is absolutely irrelevant on any machine capable of running WoW in the first place. If you are somehow eating up 100 MB then you will probably want to look into why your chat module was taking up that much memory, but otherwise, remember the two rules of program optimization:

First Rule of Program Optimization: Don’t do it.
Second Rule of Program Optimization (for experts only!): Don’t do it yet.
If you'd prefer to roll your own module system, I'd go with something like this:

Core file loads first:
Code:
addon.modules = {}

function addon:RegisterModule(name, object)
     -- Really, this function is not necessary, but it makes it much easier
     -- to add common features to all of your modules, like self:Print or
     -- other common methods. Also, an API feels cleaner than just adding
     -- stuff to your table from other files.

     self.modules[name] = object
end

function addon:ADDON_LOADED(name)
     if name ~= addonName then return end
     -- By the time this event fires for this addon, all of
     -- this addon's files and saved variables have loaded.

     -- Initialize your saved variables here.

     -- Do core initialization stuff here.

     for moduleName, moduleObject in pairs(self.modules) do
          if self.db.modules[moduleName].enable then
               moduleObject:Enable()
          end
     end
end
And in each module file, which loads after the core file:
Code:
function module:Enable()
          [color="Silver"][i]-- Do stuff here that should happen when the module loads.
end

addon:RegisterModule("SomeModule", module)
Then, set up your addon's saved variables to include something like this:
Code:
addon.db = {
     modules = {
          SomeModule = {
               enable = true, -- This module is enabled.
               someOtherSetting = 9000,
          },
          OtherModule = {
               enable = false, -- This module is NOT enabled.
               foo = "bar",
          },
     }
}
__________________
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