Library io
IO library, for advanced Lua style file manipulation.
Functions
| close( file ) | Closes a file. |
| flush() | Flushes the default output file. |
| input( file ) | Opens a new file as the default input file in "r" mode, or returns the currently opened file. |
| lines( fileName, ... ) | Same as io.input():lines( ... |
| open( filePath, mode ) | Opens a file. |
| output( file ) | Opens a new file as the default output file in "w" mode, or returns the currently opened file. |
| read( ... ) | Reads from the default input file, same as io.input():read( ... |
| type( file ) | Returns the type of the file. |
| write( ... ) | Same as io.output():write( ... |
Functions
- io.close( file )
-
Closes a file.
Environment:
SharedParameters:
-
file: If nil, closes the default output file. Otherwise closes the passed in file.
-
- io.flush()
-
Flushes the default output file.
Environment:
Shared - io.input( file )
-
Opens a new file as the default input file in "r" mode, or returns the currently opened file.
Environment:
SharedParameters:
-
file: Either nil to return the currently opened input file, a file object to set as the default input file, or a file name to open.
Return value:
(File)The default input file. -
- io.lines( fileName, ... )
-
Same as io.input():lines( ... ), but closes the file at the end of the iteration.
Environment:
SharedParameters:
-
fileName: File name to open. -
...: Iterator arguments.
-
- io.open( filePath, mode )
-
Opens a file.
Environment:
SharedParameters:
-
filePath: The file name in your files directory. Must be a .json or .txt file and cannot be in a sub-directory. -
mode: The mode to open the file with. Possible values are: "r" - text read mode, "w" - text write mode, "a" - text append mode, "rb" - binary read mode, "wb" - binary write mode, "ab" - binary append mode. Note that these are not the same as standard Lua, blame Garry.
Return values:
-
(File)Opened file or nil on failure. -
(string)The error message if the file failed to open.
-
- io.output( file )
-
Opens a new file as the default output file in "w" mode, or returns the currently opened file.
Environment:
SharedParameters:
-
file: Either nil to return the currently opened output file, a file object to set as the default output file, or a file name to open.
Return value:
(File)The default output file. -
- io.read( ... )
-
Reads from the default input file, same as io.input():read( ... ).
Environment:
SharedParameters:
-
...:
-
- io.type( file )
-
Returns the type of the file.
Environment:
SharedParameters:
-
file: File object.
Return value:
(string)For an open file, "file", for a closed file "closed file". Anything else returns nil. -
- io.write( ... )
-
Same as io.output():write( ... ).
Environment:
SharedParameters:
-
...: Data to write.
-