Naev

Module file

Lua bindings to interact with files.

Note The API here is designed to be compatible with that of LÖVE.

Functions

__gc (file) Frees a file.
__eq (f1, f2) Compares two files to see if they are the same.
new (path) Opens a new file.
open (File[, Mode="r"]) Opens a File object.
close (file) Closes a file.
read (file[, bytes]) Reads from an open file.
write (file, data[, bytes]) Reads from an open file.
seek (file, pos) Seeks in an open file.
getFilename (file) Gets the name of a file object.
getMode (file) Gets the mode a file is currently in.
getSize (file) Gets the size of a file (must be open).
isOpen (file) Checks to see if a file is open.
filetype (path) Checks to see the filetype of a path.
mkdir (dir) Makes a directory.
enumerate (dir) Returns a list of files and subdirectories of a directory.
remove (path) Removes a file or directory.


Functions

__gc (file)
Frees a file.

Parameters:

  • file File File to free.
__eq (f1, f2)
Compares two files to see if they are the same.

Parameters:

  • f1 File File 1 to compare.
  • f2 File File 2 to compare.

Returns:

    boolean true if both files are the same.
new (path)
Opens a new file.

Parameters:

Returns:

    File New file object.
open (File[, Mode="r"])
Opens a File object.

Parameters:

  • File File object to open.
  • Mode mode to open the file in (should be 'r', 'w', or 'a'). (default "r")

Returns:

    boolean true on success, false and an error string on failure.
close (file)
Closes a file.

Parameters:

  • file File File to close.

Returns:

    true on success.
read (file[, bytes])
Reads from an open file.

Parameters:

  • file File File to read from.
  • bytes number Number of bytes to read or all if ommitted. (optional)

Returns:

  1. string Read data.
  2. number Number of bytes actually read.
write (file, data[, bytes])
Reads from an open file.

Parameters:

  • file File File to write to.
  • data string Data to write.
  • bytes number Number of bytes to write. (optional)
seek (file, pos)
Seeks in an open file.

Parameters:

  • file File File to seek in.
  • pos number Position to seek to (from start of file).

Returns:

    boolean true on success.
getFilename (file)
Gets the name of a file object.

Parameters:

  • file File File object to get name of.

Returns:

    string Name of the file object.
getMode (file)
Gets the mode a file is currently in.

Parameters:

  • file File File to get mode of.

Returns:

    string Mode of the file (either 'c', 'w', 'r', or 'a')
getSize (file)
Gets the size of a file (must be open).

Parameters:

  • file File File to get the size of.

Returns:

    number Size of the file.
isOpen (file)
Checks to see if a file is open.

Parameters:

  • file File File to check to see if is open.

Returns:

    boolean true if the file is open, false otherwise.
filetype (path)
Checks to see the filetype of a path.

Parameters:

  • path string Path to check to see what type it is.

Returns:

    string What type of file it is or nil if doesn't exist.
mkdir (dir)
Makes a directory.

Parameters:

  • dir string Name of the directory to make.

Returns:

    boolean True on success.
enumerate (dir)
Returns a list of files and subdirectories of a directory.

Parameters:

  • dir string Name of the directory to check.

Returns:

    table Table containing all the names (strings) of the subdirectories and files in the directory.
remove (path)
Removes a file or directory.

Parameters:

  • path string Name of the path to remove.

Returns:

    boolean True on success.
generated by LDoc 1.5.0 Last updated 2024-11-21 07:14:26