Skip to content

Commit

Permalink
Don't eat the namespace, and use pcall
Browse files Browse the repository at this point in the history
Also move OnLogin to event handler metatable
  • Loading branch information
p3lim committed Jul 23, 2024
1 parent 6b18a2e commit 05710fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
18 changes: 18 additions & 0 deletions modules/event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,24 @@ addon = setmetatable(addon, {
return true -- unregister event
end
end)
elseif key == 'OnLogin' then
--[[ namespace:OnLogin()
Shorthand for the [`PLAYER_LOGIN`](https://warcraft.wiki.gg/wiki/PLAYER_LOGIN).
Usage:
```lua
function namespace:OnLogin()
-- player has logged in!
end
```
--]]
addon:RegisterEvent('PLAYER_LOGIN', function(self)
local successful, ret = pcall(value, self)
if not successful then
error(ret)
end
return true -- unregister event
end)
elseif IsEventValid(key) then
--[[ namespace:_event_
Registers a to an anonymous function.
Expand Down
27 changes: 6 additions & 21 deletions modules/load.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,13 @@ function addon:HookAddOn(addonName, callback)
end
end

function addon:ADDON_LOADED(addonName)
addon:RegisterEvent('ADDON_LOADED', function(self, addonName)
for _, info in next, addonCallbacks do
if info.addonName == addonName then
info.callback()
local successful, err = pcall(info.callback)
if not successful then
error(err)
end
end
end
end

function addon:PLAYER_LOGIN()
--[[ namespace:OnLogin()
Shorthand for the [`PLAYER_LOGIN`](https://warcraft.wiki.gg/wiki/PLAYER_LOGIN).
Usage:
```lua
function namespace:OnLogin()
-- player has logged in!
end
```
--]]
if addon.OnLogin then
addon:OnLogin()
end

return true
end
end)

0 comments on commit 05710fc

Please sign in to comment.