View Single Post
04-18-12, 03:18 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Originally Posted by Seerah View Post
Lua Code:
  1. frame1 = CreateFrame("frame","frame1",UIParent)
  2. frame2 = CreateFrame("frame","frame1",UIParent)
This creates 2 frames. The first is referenced by the global variable frame1 while the second is referenced by two global variables, frame1 and frame2. While the second frame's frame1 reference overwrites the first frame's reference, that does not mean that the second frame replaces the first. They both still exist.
Actually, this is incorrect. Two frames are indeed created, but the setting of the global variable from the frame name is more complex. To demonstrate, we'll run the following code.
Code:
f1=CreateFrame("Frame","f0");
f2=CreateFrame("Frame","f0");
print(f0,f1,f2);
Notice both frames are created with the name "f0", yet only the first one is stored in that global. This is confirmed by the first 2 pointers printed out being equal. This is because there's an internal check when a frame is created that restricts it to only set the frame name global if it doesn't exist.





Originally Posted by Wildbreath View Post
For example:
frame1 = CreateFrame("frame","frame1",UIParent)
frame2 = CreateFrame("frame","frame1",UIParent)

frame1 == frame2 ?
or frame2 is new widget object?

If second is right then i have a new snippet for optimize all addons
As most authors use locals and table keys rather than globals for performance improvements, this method is practically useless.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-18-12 at 03:35 PM.
  Reply With Quote