Thread: Stack overflow
View Single Post
01-09-24, 07:34 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,334
The first example, you're calling yourself instead of registering a function to run as a script. What happens when you make a function call as an argument for another function is it runs the function call immediately and uses the return value(s) as the argument(s) for the second function. In this case, you're calling yourself (SetWidgetScript()) and :SetScript() is expecting to take any returns to use for the callback script. SetWidgetScript() doesn't actually return anything, so if it wasn't repeatedly calling itself, causing the stack overflow, it would end up sending nil to :SetScript().

The second example creates a dynamic function to call SetWidgetScript() with the arguments supplied as upvalues. Unlike the first example, you aren't calling it immediately as you are just giving it a function.



It's not exactly the way I'd design this function either way as trying to call it to register multiple callbacks on the same frame will cause the previous OnShow registrations to be lost. Also the OnShow script never unregisters itself, so it'll just keep calling itself whenever it gets fired, which will keep piling :HookScript() calls on top of each other.

Mouse scripts require a "visible" frame to fire, so there's no need to delay hooking until it's shown anyway.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 01-09-24 at 07:52 PM.
  Reply With Quote