Thread Tools Display Modes
Prev Previous Post   Next Post Next
04-08-21, 02:00 PM   #1
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
AceEvent-3.0 tricked into registering non-existent events??

In my addon DynamicCam, the user can create custom situations including lists of events when to check the situation conditions.

If the user enters non-existent events, I want to show them my own error message. So I am using pcall() around RegisterEvent() to catch the errors of non-existent events.

This seemed to work quite well. But during the addon startup the event-registering function may be called more than once. It seems that with a second try, the non-existing events are registered!

Here is a minimal working example:

Lua Code:
  1. local folderName = ...
  2. DynamicCam = LibStub("AceAddon-3.0"):NewAddon(folderName, "AceEvent-3.0")
  3.  
  4. function DynamicCam:EventHandler(event)
  5.   print("EventHandler not doing anything", event)
  6. end
  7.  
  8.  
  9. local event = "nonExistingEvent"
  10.  
  11. -- First try fails with error message as expected.
  12. local result = {pcall(function() DynamicCam:RegisterEvent(event, "EventHandler") end)}
  13. if result[1] == false then
  14.   print("Did not register event:", event)
  15.   print("Error:", result[2])
  16. else
  17.   print("Registered event:", event)
  18. end
  19.  
  20. -- Second try succeeds!!
  21. print("Try again!")
  22. result = {pcall(function() DynamicCam:RegisterEvent(event, "EventHandler") end)}
  23. if result[1] == false then
  24.   print("Did not register event:", event)
  25.   print("Error:", result[2])
  26. else
  27.   print("Registered event:", event)
  28. end
  29.  
  30. -- Will lead to error, trying to unregister nonExistingEvent:
  31. DynamicCam:UnregisterAllEvents()


Why is the second try not exactly like the first one?
If I use RegisterEvent(event) instead of RegisterEvent(event, "EventHandler"), it is like that!
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » AceEvent-3.0 tricked into registering non-existent events??

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off