View Single Post
07-19-16, 08:58 PM   #5
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
It may cause taint, you don't need to replace the frame's meta, it is better to creating a wrapper of the frame like :

Lua Code:
  1. local metaF = {
  2.     __index = {
  3.         foo = function() print("bar") end
  4.     },
  5. }
  6.  
  7. function BuildFrame(...)
  8.     local f = CreateFrame("Frame", ...)
  9.  
  10.     -- Only create the meta once
  11.     if not metaF.Inited then
  12.         metaF.Inited = true
  13.         for k, v in pairs(getmetatable(f).__index) do
  14.             if not metaF.__index[k] then
  15.                 metaF.__index[k] = v
  16.             end
  17.         end
  18.     end
  19.  
  20.     -- Create the wrapper
  21.     local w = setmetatable({}, metaF)
  22.     w[0] = f[0]   -- Copy the userdata, make sure the widget API can works well with the wrapper
  23.     -- w.RealUI = f   -- You may add a ref to the real frame
  24.  
  25.     return w
  26. end
  27.  
  28. -- Now you can use it without taint
  29. local frm = BuildFrame()
  30. frm:SetBackdropColor(0,0.5,1)
  Reply With Quote