Scaleform Studio Lua API Reference: io namespace reference

io namespace reference

Description

Input/output namespace - Provides functions to create, read and write to files.

Namespaces

The standard error file handle descriptor.
The standard input file handle descriptor.
The standard output file handle descriptor.

Functions

Parameters

file :

string

The file handle to close.

Returns
This function does not return any values.

Equivalent to file:close(). If file is not specified, this function closes the default output file.

Parameters
This function does not accept any parameters.
Returns
This function does not return any values.

Equivalent to file:flush().

Parameters

file :

string

The name of the file or the file handle.

Returns

string

The file handle of the opened file or the file handle to the current 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.

Parameters

file :

string

The name of the file to be read.

Returns

fun(any*:any*)

The iterator function to read the lines of the file.

The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon..

The function will open the file and iterate over all lines of the file. When the iterator function detects the end of file, it returns nil (to finish the loop) and automatically closes the file.

The call io.lines() with no file name is similar to io.input():lines(); that is, it iterates over the lines of the default input file, except it does not close the file when the loop ends.

Parameters

file :

string

The name of the file to open.

mode :

string

The file mode to open the file with. The mode can be any of the the following:

  • "r": read mode (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.

Returns

string

The file handle of the modified file.

It returns a new file handle, or, in case of errors, nil plus an error message.

Parameters

file :

string

The name of the file or the file handle to the current output file.

Returns

string

The file handle of the opened file or the file handle to the current output file.

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

Parameters

prog :

string

The program to open.

mode :

string?

The mode for file operation.

The ? notation indicates that this type is optional: there may be zero or one instances of it.
Returns

string

The file handle to input file.

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

Parameters

fmt :

string*

The type of data to read. The formats are:

  • "*l": Reads the next line skipping the end of line, returning nil on end of file. This is the default format.
  • "*n": reads a number; this is the only format that returns a number instead of a string.
  • "*a": reads the whole file, starting at the current position. On end of file, it returns the empty string.
The * notation indicates that there may be zero or more instances of the specified type.
Returns
This function does not return any values.

Reads the file according to the format that specify what to read. For each format, the function returns a string (or a number) with the characters read, or nil if it cannot read data with the specified format. When called without formats, it uses a default format that reads the next line.

Parameters
This function does not accept any parameters.
Returns

string

A file handle to the temporary file opened for reading and writing.

This file is opened in update mode and it is automatically removed when the program ends.

Parameters

obj :

string

The object to be tested.

Returns

string

Returns the string "file" if obj is an open file handle, "closed file" if obj is a closed file handle, or nil if obj is not a file handle.

Parameters

arg1 :

any*

One or more string or number arguments.

The * notation indicates that there may be zero or more instances of the specified type.
Returns
This function does not return any values.
 io.stderr
The standard error file handle descriptor.
 io.stdin
The standard input file handle descriptor.
 io.stdout
The standard output file handle descriptor.
 io.close (file)
Closes an open file handle.
 file : string
The file handle to close.
A string of characters.  io.flush ()
Flushes the default output file.
 io.input (file) : string
When called with a file name, it opens the named file (in text mode), and sets its handle as the default input file.
 file : string
The name of the file or the file handle.
 string
The file handle of the opened file or the file handle to the current input file.
 io.lines (file) : fun(any*:any*)
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.
 file : string
The name of the file to be read.
 fun(any*:any*)
The iterator function to read the lines of the file.
The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon..
This value may be an instance of any type.  io.open (file, mode) : string
Opens a file for reading or writing.
 file : string
The name of the file to open.
 mode : string
The file mode to open the file with. [more...]
 string
The file handle of the modified file.
 io.output (file) : string
Sets the standard output file.
 file : string
The name of the file or the file handle to the current output file.
 string
The file handle of the opened file or the file handle to the current output file.
 io.popen (prog, mode) : string
Starts program prog 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").
 prog : string
The program to open.
 mode : string?
The mode for file operation.
The ? notation indicates that this type is optional: there may be zero or one instances of it.
 string
The file handle to input file.
 io.read (fmt)
Equivalent to io.input():read.
 fmt : string*
The type of data to read. [more...]
The * notation indicates that there may be zero or more instances of the specified type.
 io.tmpfile () : string
Returns a handle for a temporary file.
 string
A file handle to the temporary file opened for reading and writing.
 os.tmpname () : string
Returns a string with a file name that can be used for a temporary file.
 io.type (obj) : string
Checks whether obj is a valid file handle.
 obj : string
The object to be tested.
 string
Returns the string "file" if obj is an open file handle, "closed file" if obj is a closed file handle, or nil if obj is not a file handle.
 io.write (arg1)
Equivalent to io.output():write and writes the value of each of its arguments to the file.
 arg1 : any*
One or more string or number arguments.
The * notation indicates that there may be zero or more instances of the specified type.
 string
The name of the temporary file.
Indicates a table.
This documentation uses the term table to mean an anonymous, temporary Lua table that contains named data values. You typically use these tables to pass data or settings to a function, or to hold data returned by a function.
Indicates an object.
This documentation uses the term object to mean a named Lua table or userdata value that maintains a state. Some object types may have multiple instances existing at the same time, each with its own state; these objects typically have creation functions or accessors that you must call in order to get an instance. Some object types have only one instance, which you always access through the object's name.
Indicates a named variable within a namespace, object or table; or an element within an enumeration.Indicates a code sample.Indicates an enumeration.
This documentation uses the term enumeration to mean a named Lua table that contains only a set of constant values. These values typically identify a predefined set of options for some setting or behavior. You might pass an enumeration value to a function, or test the value returned by a function against the items in the enumeration to see which option is currently set.
Indicates a named variable within a namespace or object that has a pre-set constant value.Indicates a category: a semantic grouping of related API elements.Indicates a namespace.
This documentation uses the term namespace to mean a named Lua table that exists in only one single instance, intended as a container for an interface of related objects, functions and data variables.
Indicates an output value returned by a function.Indicates a named function within a namespace or object.Indicates an input parameter for a function.