Skip to main content

open

Function open 

Source
pub fn open(filename: string, mode: option<string>) -> option<file>
Expand description

Opens a file.

§Parameters

  • filename: the name of the file to open.
  • mode: the open mode: "r" (read — the default), "w" (write, truncating), "a" (append), or the update modes "r+", "w+", "a+". Any of them may be followed by "b" to open in binary mode on systems where it matters.

§Return value

A new file handle, or, in case of errors, nil plus an error message and a system-dependent error code. A common idiom wraps the call in assert to turn a failed open into an error.

§Examples

local f = assert(io.open("out.txt", "w"))
f:write("hello\n")
f:close()

§See also

lines, close