summaryrefslogtreecommitdiff
path: root/modules/std/singleton.qs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-17 15:22:09 +0800
committerchai <chaifix@163.com>2020-10-17 15:22:09 +0800
commit08ab881a480a73d6be005c4b4e1cf35814b53e3c (patch)
tree00297c01905cff519509598c5340a82c0fc2e941 /modules/std/singleton.qs
Diffstat (limited to 'modules/std/singleton.qs')
-rw-r--r--modules/std/singleton.qs23
1 files changed, 23 insertions, 0 deletions
diff --git a/modules/std/singleton.qs b/modules/std/singleton.qs
new file mode 100644
index 0000000..afade4b
--- /dev/null
+++ b/modules/std/singleton.qs
@@ -0,0 +1,23 @@
+
+class Singleton {
+ static func get() {
+ if( type._instance == null ) {
+ type._instance = new type();
+ }
+ return type._instance;
+ }
+}
+
+/*
+Usage:
+
+class SoundManager is Singleton {
+ func init() {
+
+ }
+}
+
+var mgr = SoundManager.get();
+
+//type is upvalue\preset value, like self
+*/ \ No newline at end of file