summaryrefslogtreecommitdiff
path: root/demo/SignalManager.lua
diff options
context:
space:
mode:
Diffstat (limited to 'demo/SignalManager.lua')
-rw-r--r--demo/SignalManager.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/demo/SignalManager.lua b/demo/SignalManager.lua
new file mode 100644
index 0000000..b7e9d6b
--- /dev/null
+++ b/demo/SignalManager.lua
@@ -0,0 +1,24 @@
+local SignalManager = {}
+SignalManager.signals = {}
+
+function SignalManager.addCallback(self, signal, func)
+ if not self.signals[signal] then self.signals[signal] = {} end
+ self.signals[signal][func] = true
+end
+
+function SignalManager.removeCallback(self, signal, func)
+ if self.signals[signal] then
+ self.signals[signal][func] = nil
+ end
+end
+
+function SignalManager.emit(self, signal, argtable)
+ local sig = self.signals[signal]
+ if not sig then return end
+
+ for f, _ in pairs(sig) do
+ f(argtable)
+ end
+end
+
+return SignalManager