WoW:Lua file: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
m (Move page script moved page Lua file to Lua file without leaving a redirect)
Line 35: Line 35:


Lua file 2 for MyAddOn
Lua file 2 for MyAddOn
<lua>
  local addonName, addonTable = ...
  local addonName, addonTable = ...
   
   
Line 41: Line 42:
   print("MyAddOn's addon table banana var is " .. addonTable.banana) -- prints 'apple'
   print("MyAddOn's addon table banana var is " .. addonTable.banana) -- prints 'apple'
  end
  end
</lua>


== Guides ==
== Guides ==

Revision as of 16:31, 13 October 2023

WoW AddOn

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

Guides