Browse Source

Lua : wip Sys

Justin Donaldson 9 years ago
parent
commit
f075a27221

+ 83 - 0
std/lua/_std/Sys.hx

@@ -0,0 +1,83 @@
+
+/*
+ * Copyright (C)2005-2016 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.
+ */
+@:coreApi
+class Sys {
+	public static inline function print( v : Dynamic ) : Void {
+		return lua.Lib.print(v);
+	}
+	public static inline function println( v : Dynamic ) : Void {
+		return lua.Lib.println(v);
+	}
+	public inline static function args() : Array<String> {
+		return lua.Boot.tableToArray(lua.Lua.arg);
+	}
+	public inline static function command( cmd : String, ?args : Array<String> ) : Int  {
+		return lua.Os.execute('$cmd ${args.join(" ")}');
+	}
+	public inline static function cpuTime() : Float {
+		return lua.Os.clock();
+	}
+
+	public inline static function exit(code : Int) : Void {
+		lua.Os.exit(code);
+	}
+
+	public inline static function getChar(echo : Bool) : Int {
+		return lua.NativeStringTools.byte(lua.Io.read(1));
+	}
+
+	// TODO
+	public inline static function environment() : Map<String,String>  return new Map();
+
+	// TODO
+	public inline static function executablePath() : String return null;
+
+	// TODO
+	public static function getCwd() : String return null;
+	// TODO
+	public static function setCwd(s : String) : Void null;
+
+	public static function getEnv(s : String) : String return lua.Os.getenv(s);
+	// TODO
+	public static function putEnv(s : String, v : String ) : Void null;
+
+
+	// TODO verify
+	public static function setTimeLocale(loc : String) : Bool  return lua.Os.setlocale(loc) != null;
+
+	// TODO
+	public static function sleep(seconds : Float) : Void null;
+
+	// TODO
+	public static function stderr() : haxe.io.Output return null;
+	public static function stdin() : haxe.io.Input return null;
+	public static function stdout() : haxe.io.Output return null;
+
+	// TODO
+	public static function systemName() : String return null;
+
+	// TODO
+	public static function time() : Float return lua.Os.time();
+
+
+}

+ 59 - 0
std/lua/_std/sys/io/File.hx

@@ -0,0 +1,59 @@
+/*
+ * Copyright (C)2005-2016 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 sys.io;
+import lua.Lua;
+import lua.Io;
+import lua.FileHandle.ReadOption;
+
+@:coreApi
+class File {
+	public static function getContent( path : String ) : String { 
+		var f = Io.open(path, "r");
+		var s = f.read(All);
+		f.close();
+		return s;
+	}
+	public static function append( path : String, binary : Bool = true ) : FileOutput {
+		// var s = getContent(path);
+
+		return null;
+	}
+	public static function copy( srcPath : String, dstPath : String ) : Void {
+		
+	}
+
+	public static function getBytes( path : String ) : haxe.io.Bytes {
+		return null;
+	}
+	public static function read( path : String, binary : Bool = true ) : FileInput {
+		return null;
+	}
+	public static function write( path : String, binary : Bool = true ) : FileOutput {
+		return null;
+	}
+	public static function saveBytes( path : String, bytes : haxe.io.Bytes ) : Void {
+		
+	}
+
+	public static function saveContent( path : String, content : String ) : Void {
+	}
+}

+ 45 - 0
std/lua/_std/sys/io/FileInput.hx

@@ -0,0 +1,45 @@
+/*
+ * Copyright (C)2005-2016 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 sys.io;
+
+import lua.FileHandle;
+
+class FileInput extends haxe.io.Input {
+	var f:FileHandle;
+
+	function new(f:FileHandle){
+		this.f = f;
+	}
+
+	inline public function seek( p : Int, pos : FileSeek ) : Void {
+		return f.seek(pos, p);
+	}
+
+	inline public function tell() : Int {
+		return f.seek();
+	}
+
+	inline public function eof() : Bool {
+		return f.read(0) == null;
+	}
+
+}

+ 41 - 0
std/lua/_std/sys/io/FileOutput.hx

@@ -0,0 +1,41 @@
+/*
+ * Copyright (C)2005-2016 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 sys.io;
+
+import lua.FileHandle;
+
+class FileOutput extends haxe.io.Output {
+	var f:FileHandle;
+
+	function new(f:FileHandle){
+		this.f = f;
+	}
+
+	public function seek( p : Int, pos : FileSeek ) : Void {
+		return f.seek(pos, p);
+	}
+
+	public function tell() : Int {
+		return f.seek();
+	}
+
+}

+ 33 - 0
std/lua/_std/sys/io/FileSeek.hx

@@ -0,0 +1,33 @@
+/*
+ * Copyright (C)2005-2016 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 sys.io;
+
+@:enum
+abstract FileSeek(String) {
+	var SeekBegin = "set";
+	var SeekCur = "cur";
+	var SeekEnd = "end";
+	@:to
+	public function toString() : String {
+		return this;
+	}
+}