summaryrefslogtreecommitdiff
path: root/modules/std/singleton.qs
diff options
context:
space:
mode:
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