Browse Source

[lua] changed lua.Boot.os_patterns to lazy initialization (fixes #9757)

Aleksandr Kuzmenko 5 years ago
parent
commit
140d8942ba
2 changed files with 27 additions and 7 deletions
  1. 13 7
      std/lua/Boot.hx
  2. 14 0
      tests/unit/src/unit/issues/Issue9757.hx

+ 13 - 7
std/lua/Boot.hx

@@ -270,13 +270,19 @@ class Boot {
 		}
 		}
 	}
 	}
 
 
-	static var os_patterns = [
-		'Windows' => ['windows', '^mingw', '^cygwin'],
-		'Linux' => ['linux'],
-		'Mac' => ['mac', 'darwin', 'osx'],
-		'BSD' => ['bsd$'],
-		'Solaris' => ['SunOS']
-	];
+	static var os_patterns(get,default):Map<String,Array<String>>;
+	static function get_os_patterns():Map<String,Array<String>> {
+		if(os_patterns == null) {
+			os_patterns = [
+				'Windows' => ['windows', '^mingw', '^cygwin'],
+				'Linux' => ['linux'],
+				'Mac' => ['mac', 'darwin', 'osx'],
+				'BSD' => ['bsd$'],
+				'Solaris' => ['SunOS']
+			];
+		}
+		return os_patterns;
+	}
 
 
 	public static function systemName():String {
 	public static function systemName():String {
 		var os:String = null;
 		var os:String = null;

+ 14 - 0
tests/unit/src/unit/issues/Issue9757.hx

@@ -0,0 +1,14 @@
+package unit.issues;
+
+class Issue9757 extends unit.Test {
+#if sys
+	static var system:Null<String>;
+
+	static public function __init__() {
+		system = Sys.systemName();
+	}
+	function test() {
+		t(system != null);
+	}
+#end
+}