View Single Post
05-27-11, 10:37 AM   #1
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
"Storing" functions

I just encountered a little problem and hope, someone can give me a hint:

I'm working on a ActionBar-Framework.

While setting the button's position (and size), I want to make sure, the button is not moved again (line 11&12).

lua Code:
  1. --[[ VOID noop()
  2.         This prevents the default UI from altering our stuff!
  3.     ]]
  4.     lib.noop = function() end
  5.  
  6.     --[[ VOID MoveButton(BUTTON button, INT sizeX, INT sizeY, ARRAY pos)
  7.         Moves a button (which is in use, meaning visible) to the correct position.
  8.         ARRAY pos is defined as an array which holds the position information as it is used in SetPoint()
  9.     ]]
  10.     lib.MoveButton = function(button, sizeX, sizeY, pos)
  11.  
  12.         button:ClearAllPoints()
  13.         button:SetSize(sizeX, sizeY)
  14.         button:SetPoint(unpack(pos))
  15.  
  16.         button.SetSize = lib.noop                                               -- don't do this anymore!
  17.         button.SetPoint = lib.noop                                              -- don't do this anymore!
  18.     end

Now I want to create an ingame-config, but obviously I can't set the buttons' positions again. I tried to "store" the original function and use it later, but with no success.

Code was:

lua Code:
  1. lib.buttonFunc[button:GetName()..'SetPoint'] = button.SetPoint

lib.buttonFunc is an array and of course, this code was executed before I noop'ed the functions. But the stored value has get noop'ed aswell, I guess because they are only function pointers, not real functions.

Can anybody give me a hint, how I can noop a function, but store it's functionality to use it later on?
__________________
  Reply With Quote