IO API

Io.close Io.flush Io.input

Functionio.lines
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. Therefore, the construction
  for line in io.lines(filename) do body end

will 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 equivalent to io.input():lines(); that is, it iterates over the lines of the default input file. In this case it does not close the file when the loop ends.
Syntax io.lines(
  • filepath : string
)
Returns function iterator
Part of CC:Tweaked
API io
ExampleIterate over lines
Iterates the lines of a file.
Code
for line in io.lines(filename) do print(line) end

Io.open Io.output

Functionio.read
See read.
Syntax io.read(
  • typingCharacter? : string
  • history? : table
  • autocomplete? : function
)
Returns string textEntered
Part of CC:Tweaked
API io
See also read
ExampleInput text
Asks a user to enter some text
Code
local str = io.read()
ExampleInput password
Inputs a hidden string.
Code
local str = io.read("*")
ExampleAutocomplete+history
Inputs with auto and hist
Code
local str = io.read(nil, {"A"}, function() return "X" end)

Io.type Io.write

This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.