io.input

Opens filename for input in text mode

Prototype

f = io.input (filename)

Description

Opens filename for input in text mode. Raises an error if it cannot.
If opened OK returns a handle to the opened file, and makes it the default input file.

If called with no argument, returns the handle to the default input file.

If called with a file handle, sets the default input file to that handle.

prev = io.input ()  -- save current input file
f = io.input ("test.txt") --> handle to new file
f:close ()  -- close that file now
io.input (prev) -- restore previous input file

Lua functions

Topics