Originally Posted by Phanx
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:
local self = CreateFrame();
local function TestFunction()
print("Hello");
end
self.TestFunction = TestFunction;
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.