Using the AddOn namespace

From Wowpedia
Jump to: navigation, search

The addon namespace is a shared table for Lua files in the same addon.

It allows for addons to access data between files without exposing/polluting variables to the global environment.

addonName, addonTable = ...

Vararg

addonName 
string - The name of your addon as set in the TOC and folder name.
addonTable 
table - The shared addon table between the Lua files of an addon.

Example

This addon defines the "foo" key on the addon table in FileA.lua and accesses it in FileB.lua

  • Test.toc
## Interface: 80300
## Version: 1.0
## Title: Test

FileA.lua
FileB.lua
  • FileA.lua
local _, addonTable = ...

addonTable.foo = "Hello"
  • FileB.lua
local addonName, addonTable = ...

print(addonName, addonTable.foo) -- prints "Test" and "Hello"

Notes

  • It's alternatively a good practice to only use a single, unique global table variable and access that from your files.

References