瀏覽代碼

[lua] add more luv bindings, add/update Table.toArray, etc.

Justin Donaldson 5 年之前
父節點
當前提交
dd2a40df30

+ 2 - 0
extra/CHANGES.txt

@@ -5,6 +5,8 @@
 	php : improved performance of `haxe.io.Bytes.get()` (#8938)
 	php : improved performance of serialization/unserialization of `haxe.io.Bytes` (#8943)
 	php : improved performance of enum-related methods in `Type` class of standard library
+    lua : lua.Lib.tableToArray moved to Table.toArray
+    lua : support for libuv/luv 1.32
 
 	Bugfixes:
 

+ 0 - 15
std/lua/Lib.hx

@@ -24,7 +24,6 @@ package lua;
 
 import lua.Lua;
 import lua.Io;
-import lua.NativeStringTools;
 
 /**
 	Platform-specific Lua Library. Provides some platform-specific functions
@@ -47,20 +46,6 @@ class Lib {
 		Io.flush();
 	}
 
-	/**
-		Copies the table argument and converts it to an Array
-	**/
-	public inline static function tableToArray<T>(t:Table<Int, T>, ?length:Int):Array<T> {
-		return Boot.defArray(PairTools.copy(t), length);
-	}
-
-	/**
-		Copies the table argument and converts it to an Object.
-	**/
-	public inline static function tableToObject<T>(t:Table<String, T>):Dynamic<T> {
-		return Boot.tableToObject(PairTools.copy(t));
-	}
-
 	/**
 		Perform Lua-style pattern quoting on a given string.
 	**/

+ 10 - 7
std/lua/Table.hx

@@ -67,13 +67,16 @@ extern class Table<A, B> implements ArrayAccess<B> implements Dynamic<B> {
         return cast obj;
     }
 
-    public inline static function toArray<T>(tbl : Table<Int,T>) : Array<T> {
-        var arr =  [];
-        PairTools.ipairsFold(tbl, (k,v,m) ->{
-            arr.push(v);
-            return arr;
-        }, arr);
-        return arr;
+	/**
+		Copies the table argument and converts it to an Object.
+	**/
+	public inline static function toObject<T>(t:Table<String, T>):Dynamic<T> {
+		return Boot.tableToObject(PairTools.copy(t));
+	}
+
+
+    public inline static function toArray<T>(tbl : Table<Int,T>, ?length:Int) : Array<T> {
+		return Boot.defArray(PairTools.copy(tbl), length);
     }
 
 	@:overload(function<A, B>(table:Table<A, B>):Void {})

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

@@ -42,7 +42,7 @@ class Sys {
 
 	public inline static function args():Array<String> {
 		var targs = lua.PairTools.copy(Lua.arg);
-		var args = lua.Lib.tableToArray(targs);
+		var args = lua.Table.toArray(targs);
 		return args;
 	}
 

+ 1 - 4
std/lua/_std/sys/FileSystem.hx

@@ -23,9 +23,6 @@
 package sys;
 
 import lua.Io;
-import lua.Os;
-import lua.Lib;
-import lua.Table;
 import haxe.io.Path;
 import lua.lib.luv.fs.FileSystem as LFileSystem;
 
@@ -40,7 +37,7 @@ class FileSystem {
 	}
 
 	public inline static function rename(path:String, newPath:String):Void {
-		var ret = Os.rename(path, newPath);
+		var ret = lua.Os.rename(path, newPath);
 		if (!ret.success) {
 			throw ret.message;
 		}

+ 2 - 2
std/lua/_std/sys/net/Socket.hx

@@ -154,9 +154,9 @@ class Socket {
 			sock.output = new SocketOutput(cast x);
 			return sock;
 		}
-		var read_arr = res.read == null ? [] : lua.Lib.tableToArray(res.read).map(convert_socket);
+		var read_arr = res.read == null ? [] : Table.toArray(res.read).map(convert_socket);
 
-		var write_arr = res.write == null ? [] : lua.Lib.tableToArray(res.write).map(convert_socket);
+		var write_arr = res.write == null ? [] : Table.toArray(res.write).map(convert_socket);
 		return {read: read_arr, write: write_arr, others: []};
 	}
 }

+ 2 - 1
std/lua/lib/luv/Os.hx

@@ -3,7 +3,8 @@
  *
  * 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,
+ * 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:
  *

+ 63 - 24
std/lua/lib/luv/fs/FileSystem.hx

@@ -126,9 +126,10 @@ extern class FileSystem {
 	@:overload(function(oldpath:String, newpath:String, flags:Int, cb:String->Bool->Void):Request {})
 	static function symlink(oldpath:String, newpath:String, flags:Int):Bool;
 
-	// @:native("fs_readlink")
-	// @:overload(function(path : String, cb : String->String->Void) : Request {})
-	// static function readlink(path : String) : String;
+	@:native("fs_readlink")
+	@:overload(function(path : String, cb : String->String->Void) : Request {})
+	static function readlink(path : String) : String;
+
 	@:native("fs_realpath")
 	@:overload(function(path:String, cb:String->String->Void):Request {})
 	static function realpath(path:String):String;
@@ -140,37 +141,75 @@ extern class FileSystem {
 	@:native("fs_fchown")
 	@:overload(function(descriptor:FileDescriptor, uid:Int, gid:Int, cb:String->Bool->Void):Request {})
 	static function fchown(descriptor:FileDescriptor, uid:Int, gid:Int):Bool;
+
+    /**
+      Not available on windows
+    **/
+	@:native("fs_lchown")
+	@:overload(function(descriptor:FileDescriptor, uid:Int, gid:Int, cb:String->Bool->Void):Request {})
+	static function lchown(descriptor:FileDescriptor, uid:Int, gid:Int):Bool;
+
+    @:native("fs_statfs")
+    @:overload(function(path:String, cb:StatFs->Bool->Void):Request{})
+    static function statfs(path:String):StatFs;
+
+    @:native("fs_opendir")
+    @:overload(function(path:String, cb:Handle->Bool->Void):Request{})
+    static function opendir(path : String) : Handle;
+
+    @:native("fs_readdir")
+    @:overload(function(dir:Handle, cb:Table<Int,NameType>->Bool->Void):Request{})
+    static function readdir(path : String) : Table<Int,NameType>;
+
+    @:native("fs_closedir")
+    @:overload(function(dir:Handle, cb:Bool->Void):Request{})
+    static function closedir(dir:Handle):Bool;
 }
 
 extern class ScanDirMarker {}
 
 @:multiReturn
 extern class ScandirNext {
-	var name:String;
-	var type:String;
+	var name : String;
+	var type : String;
+}
+
+typedef NameType = {
+    name : String,
+    type : String
 }
 
 typedef Stat = {
-	ino:Int,
-	ctime:TimeStamp,
-	uid:Int,
-	dev:Int,
-	nlink:Int,
-	mode:Int,
-	size:Int,
-	birthtime:TimeStamp,
-	gid:Int,
-	type:String,
-	rdev:Int,
-	gen:Int,
-	blocks:Int,
-	mtime:TimeStamp,
-	atime:TimeStamp,
-	blksize:Int,
-	flags:Int
+	ino       : Int,
+	ctime     : TimeStamp,
+	uid       : Int,
+	dev       : Int,
+	nlink     : Int,
+	mode      : Int,
+	size      : Int,
+	birthtime : TimeStamp,
+	gid       : Int,
+	type      : String,
+	rdev      : Int,
+	gen       : Int,
+	blocks    : Int,
+	mtime     : TimeStamp,
+	atime     : TimeStamp,
+	blksize   : Int,
+	flags     : Int
 }
 
 typedef TimeStamp = {
-	sec:Int,
-	nsec:Int
+	sec  : Int,
+	nsec : Int
+}
+
+typedef StatFs = {
+    type   : Int,
+    bsize  : Int,
+    blocks : Int,
+    bfree  : Int,
+    bavail : Int,
+    files  : Int,
+    ffree  : Int
 }

+ 11 - 11
std/lua/lib/luv/fs/Open.hx

@@ -23,16 +23,16 @@
 package lua.lib.luv.fs;
 
 enum abstract Open(String) {
-	var ReadOnly = "r";
-	var ReadOnlySync = "rs";
-	var ReadWrite = "r+";
-	var ReadWriteSync = "rs+";
-	var ReadWriteAppend = "a+";
-	var ReadWriteTruncate = "w+";
+	var ReadOnly                 = "r";
+	var ReadOnlySync             = "rs";
+	var ReadWrite                = "r+";
+	var ReadWriteSync            = "rs+";
+	var ReadWriteAppend          = "a+";
+	var ReadWriteTruncate        = "w+";
 	var ReadWriteTruncateNewFile = "wx+";
-	var ReadWriteAppendNewFile = "ax+";
-	var WriteOnly = "w";
-	var WriteNewFile = "wx";
-	var Append = "a";
-	var AppendNewFile = "ax";
+	var ReadWriteAppendNewFile   = "ax+";
+	var WriteOnly                = "w";
+	var WriteNewFile             = "wx";
+	var Append                   = "a";
+	var AppendNewFile            = "ax";
 }