Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local _M = {}
- local listeners = {}
- function _M.addListener(name, listener)
- if not name or not listener then return end
- if not listeners[name] then listeners[name] = {} end
- table.insert(listeners[name], listener)
- end
- function _M.removeListener(name, listener)
- if not name or not listener or not listeners[name] then return end
- local ind = table.indexOf(listeners[name], listener)
- if ind then table.remove(listeners[name], ind) end
- end
- function _M.dispatch(name, params)
- if not name or not listeners[name] then return end
- local l = listeners[name]
- for i = 1, #l do
- l[i](params and table.copy(params))
- end)
- end
- return _M
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement