Thread Tools Display Modes
11-03-14, 09:02 AM   #21
AlleyKat
A Warpwood Thunder Caller
 
AlleyKat's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 93
There are no objects in lua, frame is metatable with userdata, where userdata is real frame object, we are not coping userdata, so we are not creating two objects, we are just using object from another instance (another table)

Last edited by AlleyKat : 11-03-14 at 09:28 AM.
  Reply With Quote
11-03-14, 10:18 AM   #22
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Yes, but for all practical purposes, they are two different objects in Lua:

Code:
local t = {}
local f = CreateFrame("Frame")
print(t == f)
That will print "false" even after all you apply all your pointless hacks. You're completely missing the forest for the trees here.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-03-14, 07:09 PM   #23
AlleyKat
A Warpwood Thunder Caller
 
AlleyKat's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 93
I said about userdata, not tables
  Reply With Quote
11-03-14, 07:21 PM   #24
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I was addressing this:

Originally Posted by AlleyKat View Post
and now we don't care what table to use, coz they are same
They're not the same. You've just written a bunch of bloated metatable hacks to make them act like they're the same, and this is what I'm saying is absolutely pointless, and a bad programming habit besides.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-03-14, 08:29 PM   #25
AlleyKat
A Warpwood Thunder Caller
 
AlleyKat's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 93
Originally Posted by Phanx View Post
and this is what I'm saying is absolutely pointless, and a bad programming habit besides.
Nope, not pointless, my build-in table now has frame atrrs, and table of original frame works as build-in

Code:
local title, M = ...;

local anotherFrame = CreateFrame("Frame", "SomeFrame", M);
another lua file, or addon

Code:
local M = SomeFrame:GetParent();
  Reply With Quote
11-03-14, 08:40 PM   #26
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Clearly you're missing my point, and also the point of this thread -- which is about which variables must be global under the WoW addon system, which nothing you've posted has been related to -- so continuing this conversation is as pointless as tricking a table into behaving like a frame instead of just using a frame. Carry on.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-03-14, 08:49 PM   #27
AlleyKat
A Warpwood Thunder Caller
 
AlleyKat's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 93
Originally Posted by Phanx View Post
as pointless as tricking a table into behaving like a frame instead of just using a frame. Carry on.
Nope, if I want to use already created build-in table as main storage for my addon functions and data
  Reply With Quote
11-03-14, 09:07 PM   #28
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Originally Posted by AlleyKat View Post
Nope, if I want to use already created build-in table as main storage for my addon functions and data
Code:
local title, M = ...;

GLOBAL_REFERNCE_TO_MY_ADDONS_TABLE = M
does not create a seperate copy of the table but "use already created build-in table as main storage for my addon" and is no more global than the frame you created.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
11-03-14, 09:28 PM   #29
AlleyKat
A Warpwood Thunder Caller
 
AlleyKat's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 93
hey look, hey
Code:
local t, M = ...;
setfenv(1, setmetatable(M, { __index = _G }));
  Reply With Quote
11-03-14, 10:28 PM   #30
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
I still don't see how this gets you any closer to what I think you think you are gaining from the exersize but I don't think you are.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
11-03-14, 10:30 PM   #31
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by AlleyKat View Post
Nope, not pointless, my build-in table now has frame atrrs, and table of original frame works as build-in

Code:
local title, M = ...;

local anotherFrame = CreateFrame("Frame", "SomeFrame", M);
another lua file, or addon

Code:
local M = SomeFrame:GetParent();
I'm really confused by this, too, AlleyKat.

Frames are just special tables. You can store anything you want in there and use it like a regular table. I would do this, since you're creating a frame with a global name anyway:
Lua Code:
  1. local frame = CreateFrame("Frame", "MyGlobalFrameName")
  2.  
  3. frame.valueToSave = true
  4.  
  5. frame.initFunc = function()
  6.      --do stuff
  7. end
  8.  
  9. function frame:CallFromModule(var1, var2)
  10.      --do stuff for my module
  11.      return newVar
  12. end

And from another file in my addon (say, a module) or from another addon:
Lua Code:
  1. local newVar = MyGlobalFrameName:CallFromModule(var1, var2)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-04-14, 12:49 PM   #32
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,325
I'm popping in here just to tell AlleyKat, no. Just... no. Bad kat. Bad.
No separating frame userdata from their tables.

All joking aside. From the tests I did on widget objects and their data structure, it's a really bad idea to mess with the userdata placed in the created table. Even though the frame methods receive the table itself and do their own indexing operations to reference the userdata, the callback scripts get their own table reference self from C code that points to the original table created for that frame. With all the hacks needed to make a table transplant work on widget objects, it causes a major performance hit when trying to index the frame from a script. It's much better to just store the frame in your addon table than trying to transplant its innards.

Like this:
Code:
local name,addon=...;
addon.Events=CreateFrame("Frame");
__________________
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 : 11-04-14 at 12:54 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Global vars ?


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