Skip to content

Commit

Permalink
local cb not needed. Allow crash for invalid callbacks. Better to hav…
Browse files Browse the repository at this point in the history
…e stack trace and fix it in case of error
  • Loading branch information
SX authored and BuckarooBanzay committed Aug 19, 2020
1 parent 1656edd commit b9c820d
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,20 @@ beerchat.register_callback = function(trigger, fn)
return
end

local cb = beerchat.cb

if not cb[trigger] then
if not beerchat.cb[trigger] then
print(string.format('Error: Invalid callback trigger event %s, possible triggers:', trigger))
for k,_ in pairs(cb) do
for k,_ in pairs(beerchat.cb) do
print(' -> ' .. k)
end
return
end

table.insert(cb[trigger], fn)
table.insert(beerchat.cb[trigger], fn)
end

beerchat.execute_callbacks = function(trigger, ...)
local cb_list = beerchat.cb[trigger]
if not cb_list then
print('Error: Invalid trigger argument for beerchat.execute_callbacks')
-- This is internal error / dev error, stop processing current event
return false
end
local arg = {...}
if arg == nil then
print('Error: Missing arguments for beerchat.execute_callbacks')
-- This is internal error / dev error, stop processing current event
return false
end
for _,fn in ipairs(cb_list) do
local result, msg = fn(unpack(arg))
if result ~= nil then
Expand Down

0 comments on commit b9c820d

Please sign in to comment.