diff --git a/signal.lua b/signal.lua index 975d4c8..6bb435e 100644 --- a/signal.lua +++ b/signal.lua @@ -76,20 +76,20 @@ function Registry:clearPattern(p) end end --- the module -local function new() - local registry = setmetatable({}, Registry) - - return setmetatable({ - new = new, - register = function(...) return registry:register(...) end, - emit = function(...) registry:emit(...) end, - remove = function(...) registry:remove(...) end, - clear = function(...) registry:clear(...) end, - emitPattern = function(...) registry:emitPattern(...) end, - removePattern = function(...) registry:removePattern(...) end, - clearPattern = function(...) registry:clearPattern(...) end, - }, {__call = new}) +-- instancing +function Registry.new() + return setmetatable({}, Registry) end -return new() +-- default instance +local default = Registry.new() + +-- module forwards calls to default instance +local module = {} +for k in pairs(Registry) do + if k ~= "__index" then + module[k] = function(...) return default[k](default, ...) end + end +end + +return setmetatable(module, {__call = Registry.new}) diff --git a/timer.lua b/timer.lua index ef4a750..2693849 100644 --- a/timer.lua +++ b/timer.lua @@ -174,24 +174,25 @@ __index = function(tweens, key) or error('Unknown interpolation method: ' .. key) end}) --- the module -local function new() - local timer = setmetatable({functions = {}, tween = Timer.tween}, Timer) - return setmetatable({ - new = new, - update = function(...) return timer:update(...) end, - during = function(...) return timer:during(...) end, - after = function(...) return timer:after(...) end, - every = function(...) return timer:every(...) end, - script = function(...) return timer:script(...) end, - cancel = function(...) return timer:cancel(...) end, - clear = function(...) return timer:clear(...) end, - tween = setmetatable({}, { - __index = Timer.tween, - __newindex = function(_,k,v) Timer.tween[k] = v end, - __call = function(t,...) return timer:tween(...) end, - }) - }, {__call = new}) +-- Timer instancing +function Timer.new() + return setmetatable({functions = {}, tween = Timer.tween}, Timer) end -return new() +-- default instance +local default = Timer.new() + +-- module forwards calls to default instance +local module = {} +for k in pairs(Timer) do + if k ~= "__index" then + module[k] = function(...) return default[k](default, ...) end + end +end +module.tween = setmetatable({}, { + __index = Timer.tween, + __newindex = function(k,v) Timer.tween[k] = v end, + __call = function(t, ...) return default:tween(...) end, +}) + +return setmetatable(module, {__call = Timer.new})