View Single Post
03-20-13, 03:13 PM   #25
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Edit: I overlooked your correction, but the rest of my post is still relevant so I'm leaving it as-is.

Originally Posted by Nibelheim View Post
Top of first .Lua file
Lua Code:
  1. local addon, ns = ...
  2. local Funs, Settings = unpack(select(2, ...))
I'm not sure what that's supposed to do... if that's the first file to load, the second argument passed to your file is an empty table, so unpacking it won't give you any values. Maybe you meant something like this?

First file:
Code:
local ADDON_NAME, ns = ...
local Functions, Settings = {}, {}
ns[1], ns[2] = Functions, Settings
Other files:
Code:
local ADDON_NAME, ns = ...
local Functions, Settings = ns[1], ns[2]

Functions.DoSomething = function()
    -- do something
end
However, that's still a strange way to do it. There's no reason to use cryptic indices in your private table. Just use descriptive keys:

First file:
Code:
local ADDON_NAME, ns = ...
local Functions, Settings = {}, {}
ns.Functions, ns.Settings = Functions, Settings
Other files:
Code:
local ADDON_NAME, ns = ...
local Functions, Settings = ns.Functions, ns.Settings

Functions.DoSomething = function()
    -- do something
end
In the same vein, I'm not sure why you'd store functions in their own sub-table. Why not just store them directly in the top-level table?
__________________
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.

Last edited by Phanx : 03-20-13 at 03:30 PM.
  Reply With Quote