Skip to content

file*

close

(method) file*:close()
  -> suc: boolean?
  2. exitcode: ("exit"|"signal")?
  3. code: integer?

Close file.

View documents

exitcode:
    | "exit"
    | "signal"

flush

(method) file*:flush()

Saves any written data to file.

View documents

lines

(method) file*:lines(...string|integer|"L"|"a"|"l"...(+1))
  -> fun():any, ...unknown

for c in file:lines(...) do
    body
end

View documents

...(param):
    | "n" -- Reads a numeral and returns it as number.
    | "a" -- Reads the whole file.
   -> "l" -- Reads the next line skipping the end of line.
    | "L" -- Reads the next line keeping the end of line.

read

(method) file*:read(...string|integer|"L"|"a"|"l"...(+1))
  -> any
  2. ...any

Reads the file, according to the given formats, which specify what to read.

View documents

...(param):
    | "n" -- Reads a numeral and returns it as number.
    | "a" -- Reads the whole file.
   -> "l" -- Reads the next line skipping the end of line.
    | "L" -- Reads the next line keeping the end of line.

seek

(method) file*:seek(whence?: "cur"|"end"|"set", offset?: integer)
  -> offset: integer
  2. errmsg: string?

Sets and gets the file position, measured from the beginning of the file.

View documents

whence:
    | "set" -- Base is beginning of the file.
   -> "cur" -- Base is current position.
    | "end" -- Base is end of file.

setvbuf

(method) file*:setvbuf(mode: "full"|"line"|"no", size?: integer)

Sets the buffering mode for an output file.

View documents

mode:
    | "no" -- Output operation appears immediately.
    | "full" -- Performed only when the buffer is full.
    | "line" -- Buffered until a newline is output.

write

(method) file*:write(...string|number)
  -> file*?
  2. errmsg: string?

Writes the value of each of its arguments to file.

View documents