Lua Code:
function addonTable:doSomething()
It's a matter of what scope you want the function/variable to have
- Added to global table, All addons have acess to it.
- Added to "namespace" table, the current addon has access in all its .lua files
- local at the root level of a .lua file - code below it in that .lua file has access
- local inside a code chunk (if, for, anything with an "end" statement) - only code inside the chunk after the local declaration has access.
This is also effected by load sequence (.toc order). Eg. you can't use a function added to the namespace table before the file it is declared in has been loaded.
.toc
Code:
file1.lua
file2.lua
file1.lua
Code:
local addon, ns = ...
ns:RunFunc()
file2.lua
Code:
local addon, ns = ...
function ns:RunFunc()
print("Are we here yet?")
end
Errors because file1 is loaded before file2 has a chance to "create" the function.
Consider your .lua files as functions in their own right
Code:
BlizzardSpace["NameOfTheAddon"] = {}
function file1.lua("NameOfTheAddon", BlizzardSpace["NameOfTheAddon"])
local addon, ns = ... -- your code goes here
-- etc. etc.
end
function file2.lua("NameOfTheAddon", BlizzardSpace["NameOfTheAddon"])
local addon, ns = ... -- your code goes here
-- etc. etc.
end
(generalised representation)