From 08ab881a480a73d6be005c4b4e1cf35814b53e3c Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 17 Oct 2020 15:22:09 +0800 Subject: +init --- modules/std/event.qs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 modules/std/event.qs (limited to 'modules/std/event.qs') 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 -- cgit v1.1-26-g67d0