View Single Post
04-16-14, 08:27 AM   #4
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Originally Posted by Phanx View Post
That said, there's really no reason to meddle with the Blizzard metatable. It's absolutely trivial to add methods to a frame, and you don't have to "replicate" anything; definte each method once, and just add a pointer to each frame as desired:

Code:
local function DoSomething(frame)
    -- do something with the frame
end

for i = 1, 100000 do
    _G["MyButton"..i].DoSomething = DoSomething
end
Obviously you don't (I hope) have 100000 buttons, but the principle is the same. It doesn't matter how many frames you attach the function to; only one copy of the function exists.


In the above example, the function is replicated and _G["MyButton"..i].DoSomething is not a pointer to the locally defined function 'DoSomething', it's a separate copy of the function. That's what I had meant by 'replicate'.

I confirmed this with the following test...

Lua Code:
  1. local self = CreateFrame();
  2.  
  3. local function TestFunction()
  4.   print("Hello");
  5. end
  6.  
  7. self.TestFunction = TestFunction;
  8.  
  9. self:TestFunction(); -- obviously results in output: "Hello";

if you then change the locally defined function to print("Goodbye") and call self:TestFunction() again, it'll still output "Hello".


Regardless, I've added the methods to the frames directly anyway, although I see no harm what-so-ever in 'meddling' with (ie adding methods to) Blizz's table.
__________________
__________________
  Reply With Quote