I/O module¶
This module contains the required functions and types to stream handling. The distinction is made between reading from a stream (inputstream) and writing to a stream (outputstream). You can implement your own stream type as soon as they respect the following contracts.
-
io.
openRead
(filename)¶ Opens file
filename
in reading mode. This function returns aninputstream
or throws an exception if the file cannot be opened.Parameters: filename (string) – Path to the file to open. Return type: inputstream
-
io.
openWrite
(filename)¶ Opens file
filename
in writing mode. If the file already exists, it is truncated first. This function returns anoutputstream
or throws an exception if the file cannot be opened.Parameters: filename (string) – Path to the file to open. Return type: outputstream
-
io.
openAppend
(filename)¶ Opens file
filename
in appending mode. This function returns anoutputstream
or throws an exception if the file cannot be opened.Parameters: filename (string) – Path to the file to open. Return type: outputstream
-
io.
stdin
¶ Standard input stream. This attribute is readonly.
-
io.
stdout
¶ Standard output stream. This attribute is readonly.
-
io.
stderr
¶ Standard error stream. This attribute is readonly.
-
type
inputstream
¶ Default type for input streams.
-
close
()¶ Closes the current stream. If the stream is already closed, do nothing. Note that one once no more value refers to a stream, it is automatically closed.
-
eof
()¶ Returns true if the end of file is reached.
-
read
(n)¶ Reads ands returns up to
n
characters in the stream as a string. The returned string can have less thann
characters if the end of the stream is reached before.Return type: string
-
readInt
()¶ Reads and returns the next integer available in the stream. After calling this function, the stream cursor is positioned at the next non blank character or at the end of the stream if the remaining characters contains only blanks. If the read sequence cannot be converted to a valid integer, an error is thrown. If the stream is already positioned at the end-of-file or is not readable, an error is thrown.
Return type: int
-
readDouble
()¶ Reads and returns the next floating-point number available in the stream. After calling this function, the stream cursor is positioned at the next non blank character or at the end of the stream if the remaining characters contains only blanks. If the read sequence cannot be converted to a valid integer, an error is thrown. If the stream is already positioned at the end-of-file or is not readable, an error is thrown.
Return type: double
-
readString
()¶ Reads and returns the next sequence of non blank characters. After calling this function, the stream cursor is positioned at the start of the next string or at the end of the stream if the remaining characters contains only blanks. If the file is already positioned at the end-of-file or is not readable, an error is thrown.
Return type: string
-
readln
()¶ Reads ands returns the next line in the stream. After calling this function, the stream cursor is positioned at the start of the next line or at the end of the stream if no characters are available. If the stream is not readable or if no line is available, an error is thrown. Note that the line terminator is trimmed and is not returned.
Return type: string
-
-
type
outputstream
¶ Default type for output streams.
-
close
()¶ Closes the current stream. If the stream is already closed, do nothing. Note that one once no more value refers to a stream, it is automatically closed.
-
flush
()¶ Flush the stream. Useful for buffered streams.
-
print
(values)¶ Writes the arguments in the stream. The values will be converted to strings. If an argument is not convertible to a string, an error is thrown. Arguments are written without space or special formatting.
-