Thread Tools Display Modes
10-13-21, 02:39 PM   #1
cosmic_kid
A Murloc Raider
Join Date: Oct 2021
Posts: 9
Ellipses assignment?

I've been getting into WoW addon development and for the moment, I'm mainly looking through other people's code to understand what's going on. I keep seeing this type of thing all over the place and I can't, for the life of me, figure out what it means.

local _, ns = ...

They then go on to use the ns variable, but I don't know how it has any data in it. What are they assigning it to exactly?
  Reply With Quote
10-13-21, 02:51 PM   #2
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
It's a table that gets passed to all files of an addon

https://wowpedia.fandom.com/wiki/Usi...ddOn_namespace
  Reply With Quote
10-13-21, 03:06 PM   #3
cosmic_kid
A Murloc Raider
Join Date: Oct 2021
Posts: 9
Sweet, that makes a lot of sense. Thank you!
  Reply With Quote
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

WoWInterface » Developer Discussions » Lua/XML Help » Ellipses assignment?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off