[signal] Fix module name and summary.

This commit is contained in:
Lorenzo Cogotti 2023-06-01 22:41:47 +02:00
parent 9928899df1
commit dba877a190
1 changed files with 16 additions and 10 deletions

View File

@ -1,4 +1,4 @@
--- Timer utilities. --- Signal utilities.
-- --
-- This is a reworked implementation of the original signal module -- This is a reworked implementation of the original signal module
-- from the hump library (https://github.com/vrld/hump). -- from the hump library (https://github.com/vrld/hump).
@ -7,7 +7,7 @@
-- It offers functionality to register for and publish signals. -- It offers functionality to register for and publish signals.
-- Implements the Observer pattern. -- Implements the Observer pattern.
-- --
-- @module gear.timer -- @module gear.signal
-- @copyright 2010-2013 Matthias Richter -- @copyright 2010-2013 Matthias Richter
-- @copyright 2022 The DoubleFourteen Code Forge -- @copyright 2022 The DoubleFourteen Code Forge
-- @author Matthias Richter, Lorenzo Cogotti -- @author Matthias Richter, Lorenzo Cogotti
@ -21,6 +21,11 @@ Signal.__index = function(self, key)
end)() end)()
end end
function Signal:new()
return setmetatable({}, self)
end
function Signal:register(s, f) function Signal:register(s, f)
self[s][f] = f self[s][f] = f
return f return f
@ -46,38 +51,39 @@ function Signal:clear(...)
end end
end end
function Signal:emitPattern(p, ...) function Signal:emitpattern(p, ...)
for s in pairs(self) do for s in pairs(self) do
if s:match(p) then self:emit(s, ...) end if s:match(p) then self:emit(s, ...) end
end end
end end
function Signal:registerPattern(p, f) function Signal:registerpattern(p, f)
for s in pairs(self) do for s in pairs(self) do
if s:match(p) then self:register(s, f) end if s:match(p) then self:register(s, f) end
end end
return f return f
end end
function Signal:removePattern(p, ...) function Signal:removepattern(p, ...)
for s in pairs(self) do for s in pairs(self) do
if s:match(p) then self:remove(s, ...) end if s:match(p) then self:remove(s, ...) end
end end
end end
function Signal:clearPattern(p) function Signal:clearpattern(p)
for s in pairs(self) do for s in pairs(self) do
if s:match(p) then self[s] = {} end if s:match(p) then self[s] = {} end
end end
end end
-- instancing function Signal:clearall()
function Signal.new() for s in pairs(self) do
return setmetatable({}, Signal) self[s] = {}
end
end end
-- default instance -- default instance
local default = Signal.new() local default = Signal:new()
-- module forwards calls to default instance -- module forwards calls to default instance
local module = {} local module = {}