package lua

Available on lua

Input and Output Facilities

Static variables

static stderr:FileHandle

static stdin:FileHandle

static stdout:FileHandle

Static methods

static close (?file:FileHandle):Void

Function to close regular files.

static flush ():Void

Saves any written data to file.

static input (file:FileHandle):Void

static input (file:String):Void

When called with a file name, it opens the named file (in text mode), and sets its handle as the default input file. When called with a file handle, it simply sets this file handle as the default input file. When called without parameters, it returns the current default input file.

In case of errors this function raises the error, instead of returning an error code.

static lines (?file:String):NativeIterator<String>

Opens the given file name in read mode and returns an iterator function that, each time it is called, returns a new line from the file.

static open (filename:String, ?mode:String):FileHandle

This function opens a file, in the mode specified in the string mode. It returns a new file handle, or, in case of errors, null plus an error message.

The mode string can be any of the following:

  • "r": read mode (the default)
  • "w": write mode
  • "a": append mode
  • "r+": update mode, all previous data is preserved
  • "w+": update mode, all previous data is erased
  • "a+": append update mode, previous data is preserved, writing is only allowed at the end of file

The mode string can also have a b at the end, which is needed in some systems to open the file in binary mode. This string is exactly what is used in the standard C function fopen.

static output (?file:String):FileHandle

static popen (command:String, ?mode:String):FileHandle

Starts program command in a separated process and returns a file handle that you can use to read data from this program (if mode is "r", the default) or to write data to this program (if mode is "w").

This function is system dependent and is not available on all platforms.

static read (?filename:String):String

static read (?count:Int):String

static tmpfile ():FileHandle

Returns a handle for a temporary file. This file is opened in update mode and it is automatically removed when the program ends.

static type (obj:FileHandle):IoType

Checks whether obj is a valid file handle.

static write (v:Rest<String>):Void

Writes the value of each of its arguments to the file. The arguments must be strings or numbers. To write other values, use Lua.tostring or NativeStringTools.format before write.

© 2005–2016 Haxe Foundation
Licensed under a MIT license.