Browse Source

[lua] give proper eof behavior for sys.io.Process

Justin Donaldson 7 years ago
parent
commit
bb3959096e
2 changed files with 22 additions and 4 deletions
  1. 4 2
      std/lua/_std/sys/io/FileInput.hx
  2. 18 2
      std/lua/_std/sys/io/Process.hx

+ 4 - 2
std/lua/_std/sys/io/FileInput.hx

@@ -67,7 +67,7 @@ class FileInput extends haxe.io.Input {
 		}
 		}
 		return NativeStringTools.byte(byte);
 		return NativeStringTools.byte(byte);
 	}
 	}
-			
+
 	override function readBytes( s : Bytes, pos : Int, len : Int ) : Int {
 	override function readBytes( s : Bytes, pos : Int, len : Int ) : Int {
 		if(eof()) throw new haxe.io.Eof();
 		if(eof()) throw new haxe.io.Eof();
 		return super.readBytes(s, pos, len);
 		return super.readBytes(s, pos, len);
@@ -87,7 +87,9 @@ class FileInput extends haxe.io.Input {
 				if (len == 0) break;
 				if (len == 0) break;
 				total.addBytes(buf,0,len);
 				total.addBytes(buf,0,len);
 			}
 			}
-		} catch( e : Eof ) _eof = true;
+		} catch( e : Eof ) {
+			_eof = true;
+		}
 		return total.getBytes();
 		return total.getBytes();
 	}
 	}
 
 

+ 18 - 2
std/lua/_std/sys/io/Process.hx

@@ -127,9 +127,20 @@ private class ProcessInput extends haxe.io.Input {
 	var b : Pipe;
 	var b : Pipe;
 	var buf : String;
 	var buf : String;
 	var idx : Int;
 	var idx : Int;
+	var _eof:Bool;
 
 
 	public function new(pipe:Pipe) {
 	public function new(pipe:Pipe) {
 		b = pipe;
 		b = pipe;
+		_eof = false;
+	}
+
+	inline public function eof() : Bool {
+		return _eof;
+	}
+
+	override function readBytes( s : Bytes, pos : Int, len : Int ) : Int {
+		if(eof()) throw new haxe.io.Eof();
+		return super.readBytes(s, pos, len);
 	}
 	}
 
 
 	override public function readByte() {
 	override public function readByte() {
@@ -146,7 +157,10 @@ private class ProcessInput extends haxe.io.Input {
 			// process io until we read our input (emulate blocking)
 			// process io until we read our input (emulate blocking)
 			while (pending) Loop.run();
 			while (pending) Loop.run();
 		}
 		}
-		if (buf == null) throw new haxe.io.Eof();
+		if (buf == null){
+			_eof = true;
+			throw new haxe.io.Eof();
+		}
 		if (err_str != null) throw err_str;
 		if (err_str != null) throw err_str;
 		var code = NativeStringTools.byte(buf, ++idx);
 		var code = NativeStringTools.byte(buf, ++idx);
 		return code;
 		return code;
@@ -165,7 +179,9 @@ private class ProcessInput extends haxe.io.Input {
 					total.addBytes(buf,0,len);
 					total.addBytes(buf,0,len);
 				if (len < bufsize)  break;
 				if (len < bufsize)  break;
 			}
 			}
-		} catch( e : Eof ) {}
+		} catch( e : Eof ) {
+			_eof = true;
+		}
 		return total.getBytes();
 		return total.getBytes();
 	}
 	}