View Single Post
10-13-21, 10:42 PM   #4
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
For a more in-depth explanation, ... in Lua is called a vararg, short for variable arguments. It is used when defining a function when the number of arguments being passed to it is unknown.

Lua Code:
  1. function fooBar(...)
  2.     local test1, test2 = ...
  3.     print(test1, test2)
  4. end
  5.  
  6. fooBar("apple")
  7. fooBar("orange", "banana")

There's another level to WoW's coding we don't see, which is written in C++. When this internal structure loads an addon, each file in the addon is actually one big function.

We see:

Lua Code:
  1. local _, ns = ...
  2. -- rest of our file

What's actually happening:

Lua Code:
  1. function addonFile(...)
  2.     local _, ns = ...
  3.     -- rest of our file
  4. end
  5.  
  6. addonFile("Name of AddOn", privateTable)

This privateTable is shared across all loaded files within an addon, basically each .toc file gets its own table.

Last edited by Kanegasi : 10-13-21 at 10:45 PM.
  Reply With Quote