Kaynağa Gözat

[lua] create Os extern module for luv, and migrate some functions there

Justin Donaldson 5 yıl önce
ebeveyn
işleme
1a5eddc076
3 değiştirilmiş dosya ile 46 ekleme ve 9 silme
  1. 3 3
      std/lua/_std/Sys.hx
  2. 0 6
      std/lua/lib/luv/Misc.hx
  3. 43 0
      std/lua/lib/luv/Os.hx

+ 3 - 3
std/lua/_std/Sys.hx

@@ -23,7 +23,7 @@
 import lua.Boot;
 import lua.Io;
 import lua.Lua;
-import lua.Os;
+import lua.lib.luv.Os;
 import lua.lib.luv.Misc;
 import sys.io.FileInput;
 import sys.io.FileOutput;
@@ -109,11 +109,11 @@ class Sys {
 		Misc.chdir(s);
 
 	public inline static function getEnv(s:String):String {
-		return Misc.os_getenv(s);
+		return Os.getenv(s);
 	}
 
 	public inline static function putEnv(s:String, v:String):Void {
-		Misc.os_setenv(s, v);
+		Os.setenv(s, v);
 	}
 
 	public inline static function setTimeLocale(loc:String):Bool {

+ 0 - 6
std/lua/lib/luv/Misc.hx

@@ -26,9 +26,6 @@ package lua.lib.luv;
 extern class Misc {
 	public static function chdir(path:String):Bool;
 
-	public static function os_homedir():String;
-	public static function os_tmpdir():String;
-	public static function os_get_passwd():String;
 	public static function cpu_info():Table<Int, CpuInfo>;
 
 	public static function cwd():String;
@@ -38,9 +35,6 @@ extern class Misc {
 	public static function get_free_memory():Int;
 	public static function getpid():Int;
 
-	public static function os_getenv(env:String):String;
-	public static function os_setenv(env:String, value:String):Void;
-
 	// TODO Windows only?
 	public static function getuid():Int;
 	public static function setuid(from:Int, to:Int):String;

+ 43 - 0
std/lua/lib/luv/Os.hx

@@ -0,0 +1,43 @@
+/*
+ * Copyright (C)2005-2019 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+package lua.lib.luv;
+
+@:luaRequire("luv")
+extern class Os {
+    @:native("os_homedir")
+	public static function homedir():String;
+
+    @:native("os_tmpdir")
+	public static function tmpdir():String;
+
+    @:native("os_get_passwd")
+	public static function get_passwd():String;
+
+    @:native("os_getenv")
+	public static function getenv(env:String):String;
+
+    @:native("os_setenv")
+	public static function setenv(env:String, value:String):Void;
+
+}
+