Your code doesn't work because:
1. You have a typo. There is no such function as "hooksecurefun" -- it needs a "c" on the end. Your code should be raising an "attempt to call a nil value" error here. If you don't already have
BugSack, go get it now. Trying to write or edit addon code without it (or some other tool to show you Lua errors, and no, the default error display is not good enough) is kind of like trying to assemble a jigsaw puzzle while wearing a blindfold -- technically you can do it, but why would you want to torture yourself?
2. You're passing a variable "frame" that you didn't define anywhere, which means you're looking for it in the global namespace. Ideally it should not exist there either, but since it's so generic, it's reasonably possible that some other addon (or even the default UI) is leaking a variable with that name, in which case the odds are probably better that you'll win the lottery and also gain telekinetic superpowers after being attacked by flying radioactive unicorn kittens than that the leaked "frame" variable will be pointing to a table with a "RegisterUpdateFunc" method attached to it. If no other addons are leaking a "frame" variable, this should also be raising a Lua error.
3. The function you're passing accepts only one argument, which you've also named "frame", which is problematic because:
3a. A function named "RegisterUpdateFunc" probably does not accept a frame name or reference as its only argument. It's far more likely that it requires a function as its only argument, and more likely still that it requires multiple arguments including a function. Post-hook functions get the same exact arguments as the original function, so do take note of what arguments the function you're hooking receives, or if you're not going to use any of the arguments, don't bother naming any.
3b. An argument named "frame" is far more likely to be a frame reference than a frame name, and comparing a frame reference to a frame name -- eg.
if UIParent == "UIParent" then -- will always fail, because a frame name cannot be equal to a string.
4. If you've already declared SUF as an optional dependency for your addon, or if your addon's name comes after SUF in alphabetical order, or SUF loaded before your addon for some other reason, then your addon will never receive an ADDON_LOADED event for SUF, because by the time WoW even figures out that your addon exists, SUF has already loaded.
-----------------------------------------------------------------------------
Here's what you need to do:
1. Add
ShadowedUnitFrames to the OptionalDependencies field in your addon's TOC file if you haven't already. If your addon is skinning, or anchoring things to things from, more than 3-5 addons, skip this step.
2. Add this code somewhere in your addon:
Code:
local function DoStuff()
-- do stuff with the SUFUnitplayer frame here
end
if SUFUnitplayer then
DoStuff()
elseif ShadowUF then
hooksecurefunc(ShadowUF.Units, "LoadUnit", function(self, unit)
if unit == "player" then
DoStuff()
end
end)
end
3. If you skipped Step 1, add this right
before the final "end" in the code above:
Code:
else
local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function(self, event, addon)
if addon == "ShadowedUnitFrames" then
hooksecurefunc(ShadowUF.Units, "LoadUnit", function(self, unit)
if unit == "player" then
DoStuff()
end
end)
end
end)