No problem.
The documentation of Inspect.Addon.Detail() says it is "The "data" table provided to the addon at load time.". Whatever that's good for.
Well I make most of my functions local to avoid name clashing.
All of my files start with
Code:
local identifier = (...).identifier
local addon = (...).data
-- Make local copies of globals here
local print = print
...
setfenv(1, addon)
Module1 = Module1 or { }
local function privateMethod1()
...
end
function Module1.InternalAddonMethod1()
...
end But after I learned there is a dedicated private table provided by Rift I'm going to switch to that instead of (...).data now. Plus I don't want the private table to be queryable by any Rift API.
After the setfenv everything is declared inside the addon table. First it saves me some tiping and second I won't pollute the global namespace if I accidentally forget the "local" keyword. I use the Addon:Method() syntax only for "instance" methods where the "self" argument varies (i.e. static or instance method), which is not required for static modules without inheritance and saves the passing of one parameter.
I try to follow the public/private ideology of OO programming. In this example privateMethod1 would be "private" to Module1. In contrary InternalAddonMethod1 is "public", but only usable inside my Addon (like "internal" in C#). Module1 in this example is more comparable to a namespace (or static class) than a class.
For classes I use the colon syntax in the public part:
Code:
setfenv(1, addon)
Class1 = { }
local function private1(self)
end
-- Callable with instance:Public1()
local function Public1(self)
-- Factory method for creating an instance of "Class"
function Class1.New()
local result = { } -- or UI.CreateFrame(...) etc
result.Public1 = Public -- Or set metatable if result is not a Frame
return result
end There are many ways to do the latter. With or without metatable, declaring all public methods locally inside Class1.New() or not and more. But the result is the same: some functions are usable by others and some aren't, which I think is what the OP asked for.
Using the MyAddon table as the container for the public API is a good idea. I like that.
Bookmarks