summaryrefslogtreecommitdiff
path: root/modules/std/event.qs
diff options
context:
space:
mode:
Diffstat (limited to 'modules/std/event.qs')
-rw-r--r--modules/std/event.qs42
1 files changed, 42 insertions, 0 deletions
diff --git a/modules/std/event.qs b/modules/std/event.qs
new file mode 100644
index 0000000..d4f2a10
--- /dev/null
+++ b/modules/std/event.qs
@@ -0,0 +1,42 @@
+import debug for debug;
+
+class event {
+ func init() {
+ self._func = []; // callback functions list
+ }
+
+ func clear() {
+ self._func.clear();
+ }
+
+ func += (fn) {
+ if(typeof(fn) != "function")
+ debug.assert("wrong type");
+ if(!self._func.contains(fn))
+ self._func.push(fn);
+ else
+ debug.logError("已经存在这个方法");
+ }
+
+ func -= (fn) {
+ if(typeof(fn) != "function")
+ debug.assert("wrong type");
+ self._func.remove(fn);
+ }
+
+ func () (...){
+ foreach(var fn in self._func) {
+ fn(...);
+ }
+ }
+}
+
+/*
+var Say = new event();
+Say += func(str) {
+ io.print(str);
+}
+Say("hi");
+Say.clear();
+
+*/ \ No newline at end of file