-- local _broadcast = {} local EventMsgCenter = {} EventMsgCenter.registerMsg = function(e, callback, first) if _broadcast[e] == nil then _broadcast[e] = {} end first = first or false if not first then table.insert(_broadcast[e], callback) else table.insert(_broadcast[e], 1, callback) end end EventMsgCenter.unRegisterMsg = function(e, callback) if _broadcast[e] == nil or callback == nil then return end table.remove(_broadcast[e], callback) end EventMsgCenter.unRegisterAllMsgByEvent = function(e) if _broadcast[e] == nil then return end _broadcast[e] = nil end EventMsgCenter.unRegisterAllMsg = function() _broadcast = {} end EventMsgCenter.sendMsg = function(e, ...) local callbacks = _broadcast[e] if callbacks == nil then return end for _, f in ipairs(callbacks) do if f ~= nil then f(...) end end end return EventMsgCenter