Browse Source

Merge branch 'development' into feature/libuv-prepare

Simon Krajewski 5 years ago
parent
commit
2e2f16cf89

+ 12 - 0
std/lua/NativeStringTools.hx

@@ -145,6 +145,18 @@ extern class NativeStringTools {
 		function must be a Lua function without upvalues.
 	**/
 	public static function dump(d:Dynamic):Dynamic;
+
+
+    /**
+        Returns a string that is the concatenation of n copies of
+        the string s separated by the string sep. The default value
+        for sep is the empty string (that is, no separator).
+        Returns the empty string if n is not positive.  (Note that
+        it is very easy to exhaust the memory of your machine with
+        a single call to this function.)
+    **/
+    public static function rep(s:String, n : Int, ?sep : String) : String;
+
 }
 
 @:multiReturn extern class StringFind {

+ 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;
+
+}
+

+ 31 - 0
std/php/JsonSerializable.hx

@@ -0,0 +1,31 @@
+/*
+ * 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 php;
+
+/**
+	@see https://www.php.net/manual/en/class.jsonserializable.php
+**/
+@:native('JsonSerializable')
+extern interface JsonSerializable<T> {
+	private function jsonSerialize():T;
+}

+ 6 - 1
std/php/_std/Array.hx

@@ -26,7 +26,7 @@ import php.ArrayIterator as NativeArrayIterator;
 using php.Global;
 
 @:coreApi
-final class Array<T> implements ArrayAccess<Int, T> implements IteratorAggregate<T> {
+final class Array<T> implements ArrayAccess<Int, T> implements IteratorAggregate<T> implements JsonSerializable<NativeIndexedArray<T>> {
 	public var length(default, null):Int;
 
 	var arr:NativeIndexedArray<T>;
@@ -234,6 +234,11 @@ final class Array<T> implements ArrayAccess<Int, T> implements IteratorAggregate
 		return new NativeArrayIterator(arr);
 	}
 
+	@:noCompletion @:keep
+	function jsonSerialize():NativeIndexedArray<T> {
+		return arr;
+	}
+
 	static function wrap<T>(arr:NativeIndexedArray<T>):Array<T> {
 		var a = new Array();
 		a.arr = arr;