View Single Post
06-24-15, 10:43 AM   #4
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by Resike View Post
I'm pretty sure it's added the the global table, since you can only reach it with that reference. But i could be wrong.
I don't think virtual object names are stored in there because I did a test:

In the .toc I had 3 files in this order of execution:

test1.lua
test2.xml
test3.lua

test1.lua had this:
Lua Code:
  1. A_GLOBAL_NAME = "hello";
  2. print(A_GLOBAL_NAME)

test2.lua had this:
XML Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/">   
  2.     <Frame name="A_GLOBAL_NAME" inherits="UIPanelDialogTemplate" virtual="true" />
  3. </Ui>

test3.lua had this:
Lua Code:
  1. print(A_GLOBAL_NAME)
  2. local f = CreateFrame("Frame", nil, UIParent, "A_GLOBAL_NAME")
  3. f:SetSize(500, 500)
  4. f:SetPoint("CENTER", UIParent, "CENTER")
  5. f:Show()

And basically test1.lua printed "hello" and so did test3.lua which means A_GLOBAL_NAME was never overwritten but also the frame inheritted from the virtual object named A_GLOBAL_NAME was successfully displayed as well.

EDIT: I also tried altering the XML virtual objects name to "SOME_OTHER_NAME" and in the test3.lua file I did this:

print(_G["SOME_OTHER_NAME"])

which printed nil so no, its definitely not in the _G table

It would also explain why CreateFrame's 4th argument "template" for example requires the template/virtual object's name to be a string or a comma-separated string list of names. If you do not supply a string and attempt to use the virtual objects name as a global variable instead then the system cannot find the virtual template because it reads this as a nil value. A global variable name is never created for the virtual/template object which is one reason why its efficient. (at least to my understanding)

(It could however be in some sort of sub-table of the global table which I am unaware of)

Last edited by Mayron : 06-24-15 at 11:42 AM.
  Reply With Quote