Hi guyz.
I have made a function to execute code in the next frame, mainly for getting correct GetLeft(), GetRight(), GetPoint() values after changing the anchor point of a Frame (because the data that those functions return is not updated until the next frame):
Lua Code:
-- Frame to execute code in the next frame
local _RunNextFrame = CreateFrame("Frame") -- Frame whose OnUpdate will execute the functions in the next frame
_RunNextFrame:Hide() -- OnUpdate disabled by default
-- OnUpdate script which iterates thru all the functions stored in the frame to execute them
_RunNextFrame:SetScript("OnUpdate", function(self)
for i = 1, #self do
self[i]() -- Executing function
self[i] = nil -- Removing the reference to the function (to be garbage collected)
end
self:Hide() -- Disabling OnUpdate
end)
-- RunNextFrame()
-- Executes a function in the next frame.
local function RunNextFrame(Function)
_RunNextFrame[#_RunNextFrame + 1] = Function -- Storing a reference to the function in the frame
_RunNextFrame:Show() -- Enabling the OnUpdate of the frame
end
-- Example application
-- Getting the distance from the left edge of the screen to the right edge of the PlayerFrame after changing its anchor point
local PlayerFrameRight
PlayerFrame:ClearAllPoints()
PlayerFrame:SetPoint("CENTER", UIParent, "CENTER", -255, 20)
RunNextFrame(function()
PlayerFrameRight = PlayerFrame:GetRight()
end)
The question is: Will the anonymous function that I pass as argument to RunNextFrame() be garbage collected?