Thread Tools Display Modes
10-27-10, 10:08 AM   #1
eberkain
A Fallenroot Satyr
Join Date: Nov 2009
Posts: 20
What are the vararg parameters passed to your lua files?

I've been digging for a while now, and have not found a consice answer.

Can someone please explain this statement that I see as the first thing in some other peoples code, or direct me to a description.

local addonName, addonTable = ...

Someone said this on a forum comment on wowace...

"The first vararg parameter passed into your Lua files contains the folder name of the currently loading addon."

So, its a string then? From what I gather the second is a table that can only be accessed by lua files in your specific addon. Are there only the two vararg params passed at the start of your lua files? or are there more?

I've so far found wowprogramming.com to be the best reference to the API, but could not find anything on there about this to save my life.
  Reply With Quote
10-27-10, 10:22 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
Yes, the first parameter is a string. It is the name of your addon. Which also happens to be the name of the folder it is in as well.

You can use it for say the ADDON_LOADED event to check if it is yours without hard coding the name of your addon at all.

eg:

function OnEvent(self,event,arg1)
if event == ADDON_LOADED and arg1 == addonName then
print("Your addon named ", addonName, " has just been loaded")
end

The second parameter is indeed a table which is empty at first until you fill it with the information you want your addon to use.


file1.lua
local addonName, addonTable = ...
addonTable.variable1 = 3

file2.lua
local addonName,addonData = ...
print(addonData.variable1)

this will display 3 as long as file1's data setting functions are called before the display functions in file2 are called

As you can see it doesn't matter what you call the values in each file as long as you use the values you used in that file to reference the data as a whole.


I use these alot now in my addons as it allows me to break my addons up into multiple files that tend to be used in multiple addons. Because the addon Name isn't referenced directly it makes sense regardless of which addon they are used in.

From the wow forum post discussing this they only mentioned the use of these 2 variables. Whether or not they have added more since I don't know.

I hope that helps you somewhat.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
10-27-10, 01:58 PM   #3
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
if you ever want to test to see if they added more variables, you could add

print(...) to the first line of your code, and it will print everythign the vararg passed.

I use that quite often when im not sure about everything being sent

such as

frame:SetScript("OnClick", function(...) print(...) end)

this should print the frame that called the onclick event and which mouse button was used.
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » What are the vararg parameters passed to your lua files?


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