WoW:Lua file: Difference between revisions
Jump to navigation
Jump to search
m (→Parameters) |
mNo edit summary |
||
Line 45: | Line 45: | ||
* [[Lua basics]] | * [[Lua basics]] | ||
[[Category:UI technical details]] |
Revision as of 04:11, 14 May 2020
WoW AddOn Lua files are the code files for a WoW AddOn. This article describes the format for a WoW Lua file as a part of an WoW AddOn.
References
Summary
.lua files contain the Lua code for a particular addon (such as its functions, variables, etc.), as well as instructions that run while addon is being loaded by the client. The file must be present if listed in the TOC file, and may or may not have the same name (plus extension) as its parent folder for the addon to be recognized by the client.
Example
-- Lua file for MyAddOn function MyAddOn_OnLoad() print("MyAddOn is started") end
Parameters
In WoW Lua files have file parameters passed when the Lua file is loaded, which can be accessed via standard Lua ellipses.
- addonName (string) - the addon name that is the addon's folder name in the 'Interface\AddOns' WoW folder
- addonTable (table) - a singular pre-created Lua table that is for the addon's private use, starts empty, not referenced in the global table, and is the same table passed to all Lua files loaded during the AddOn's load under the AddOn's folder, or referenced outside the folder during that AddOns load.
Example
For the 'MyAddOn' AddOn in the 'Interface\AddOns\MyAddOn' folder:
MyAddOn TOC file
myaddon1.lua myaddon2.lua myaddon.xml
Lua file 1 for MyAddOn
local addonName, addonTable = ... addonTable.banana = "apple"
Lua file 2 for MyAddOn
local addonName, addonTable = ... function MyAddOn_OnLoad() print("MyAddOn's name is " .. addonName) -- prints 'MyAddOn' print("MyAddOn's addon table banana var is " .. addonTable.banana) -- prints 'apple' end