lovr.filesystem.newFile
EditOpens 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
Name | Type | Description |
path | string | The path of the file to open. |
mode | OpenMode |
The mode to open the file in (r , w , or a ).
|
Returns
Name | Type | Description |
file | File | A new file object, or nil if an error occurred. |
error | string | 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