lovr.filesystem.newFile

Edit

Opens a file, returning a File object that can be used to read/write the file contents.

Normally you can just use lovr.filesystem.read, lovr.filesystem.write, etc. However, those methods open and close the file each time they are called. So, when performing multiple operations on a file, creating a File object and keeping it open will have less overhead.

file, error = lovr.filesystem.newFile(path, mode)

Arguments

NameTypeDescription
pathstring The path of the file to open.
modeOpenMode The mode to open the file in (r, w, or a).

Returns

NameTypeDescription
fileFile A new file object, or nil if an error occurred.
errorstring The error message, if an error occurred.

Example

function lovr.load()
  local file = lovr.filesystem.newFile('asdf.txt', 'w')
  file:write('asdf')
  file:release()
end

See also