• Announcement: Lua.org now officially recommends this forum as a meeting place for the Lua community

Ellipses assignment outside of a function? (1 Viewer)

cosmic_kid

Newcomer
Joined
Oct 13, 2021
Messages
2
Reaction score
1
I'm looking at some WoW addon code and I keep seeing stuff like this at the top of scripts:

local _, ns = ...

What exactly is happening here? It's impossible to search for on Google.
 

Anonymous

Newcomer
Joined
Oct 13, 2021
Messages
8
Reaction score
1
It's a multiple assignment. For example, if you have a function test, that returns three numbers:
Code:
function test()
    return 1, 2, 3
end
You can assign them to the variables a, b, and c, in a single line.
Code:
a, b, c = test()
The underscore in local, _, ns = ... means that the second return value is discarded.
 

cosmic_kid

Newcomer
Joined
Oct 13, 2021
Messages
2
Reaction score
1
Hey guys, I appreciate the comments. So I found out from another forum specific to WoW addon development that every script in a WoW addon is passed the name of the addon and a namespace table (hence "ns"). This table is used to append functionality to be passed through the different scripts in the addon because you cant import other lua files in the WoW environment. Once again, thanks for the replies.
 
Top