Przeglądaj źródła

use `neko.vm.Module.local()` to implement `Sys.programPath()`

Andy Li 9 lat temu
rodzic
commit
c4c4554ff9
1 zmienionych plików z 16 dodań i 20 usunięć
  1. 16 20
      std/neko/_std/Sys.hx

+ 16 - 20
std/neko/_std/Sys.hx

@@ -126,10 +126,12 @@
 	}
 
 	public static function programPath() : String {
-		#if interp
+		#if macro
+		return null;
+		#elseif interp
 		return new String(sys_program_path());
 		#else
-		return sys_program_path();
+		return sys_program_path;
 		#end
 	}
 
@@ -157,29 +159,23 @@
 	private static var sys_exe_path = neko.Lib.load("std","sys_exe_path",0);
 	#if interp
 	private static var sys_program_path = neko.Lib.load("std","sys_program_path",0);
-	#else
+	#elseif !macro
 	// It has to be initialized before any call to loadModule or Sys.setCwd()...
 	private static var sys_program_path = {
-		switch ([for (m in neko.vm.Loader.local().getCache().keys()) m]) {
-			case [m]:
+		var m = neko.vm.Module.local().name;
+		try {
+			sys.FileSystem.fullPath(m);
+		} catch (e:Dynamic) {
+			// maybe the neko module name was supplied without .n extension...
+			if (!StringTools.endsWith(m, ".n")) {
 				try {
-					var p = sys.FileSystem.fullPath(m);
-					function() return p;
+					sys.FileSystem.fullPath(m + ".n");
 				} catch (e:Dynamic) {
-					// maybe the neko module name was supplied without .n extension...
-					if (!StringTools.endsWith(m, ".n")) {
-						try {
-							var p = sys.FileSystem.fullPath(m + ".n");
-							function() return p;
-						} catch (e:Dynamic) {
-							function() return m;
-						}
-					} else {
-						function() return m;
-					}
+					m;
 				}
-			case modules:
-				function() return throw "cannot detemine the main module from cache: " + modules;
+			} else {
+				m;
+			}
 		}
 	}
 	#end