Game Development Reference
In-Depth Information
io.output ( [file] )
This function is similar to
io.input
but operates on the default output file instead. Using this
function, you can redirect the output to the file you want. Here's an example of how it's used:
oldIOFile = io.output()
io.output("mynewfile.txt")
io.write("Hello world")
io:output():close()
io.output(oldIOFile)
io.read ( … )
This function is equivalent to
io.input():read()
.
print(io.read())
io.tmpfile ( )
This function returns a handle for a temporary file; the file is opened in update mode and removed
automatically when the program ends.
fh = io.tmpfile()
fh:write("Some sample data")
fh:flush()
-- Now let's read the data we just wrote
fh:seek("set", 0)
content = fh:read("*a")
print("We got : ", content)
io.type ( obj )
This function returns the result if the handle specified by
obj
is a valid file handle. It returns the string
"file"
if
obj
is an open file handle and the string
"closed file"
if
obj
is a closed file handle. It
returns
nil
if
obj
is not a file handle.
print(io.type(fh)) - prints nil as fh is nil
fh = io.input()
print(io.type(fh))
io.write ( … )
This function is equivalent to
io.output():write()
.
io.write("Hello World")