local this = {}
function this.extend(scope)
local on = {}
local once = {}
function scope.on(event, callback)
if on[event] == nil then
on[event] = {}
end
table.insert(on[event], callback)
end
function scope.once(event, callback)
if once[event] == nil then
once[event] = {}
end
table.insert(once[event], callback)
end
function scope.emit(event, ...)
if once[event] ~= nil then
local onces = once[event]
once[event] = nil
for _, callback in ipairs(onces) do
if callback(unpack(arg)) == false then
return false
end
end
end
if on[event] ~= nil then
for _, callback in ipairs(on[event]) do
if callback(unpack(arg)) == false then
return false
end
end
end
end
end
return this