lovr.filesystem
EditThe lovr.filesystem
module provides access to the filesystem.
All files written will go in a special folder called the "save directory". The location of the save directory is platform-specific:
Windows | C:\Users\<user>\AppData\Roaming\LOVR\<identity> |
macOS | /Users/<user>/Library/Application Support/LOVR/<identity> |
Linux | /home/<user>/.local/share/LOVR/<identity> |
Android | /sdcard/Android/data/<identity>/files |
<identity>
is a unique identifier for the project, and can be set in lovr.conf
. On Android, the identity can not be changed and will always be the package id (e.g. org.lovr.app
).
When files are read, they will be searched for in multiple places. By default, the save directory is checked first, then the project source (folder or zip). That way, when data is written to a file, any future reads will see the new data. The t.saveprecedence
conf setting can be used to change this precedence.
Conceptually, lovr.filesystem
uses a "virtual filesystem", which is an ordered list of folders and zip files that are merged into a single filesystem hierarchy. Folders and archives in the list can be added and removed with lovr.filesystem.mount
and lovr.filesystem.unmount
.
LÖVR extends Lua's require
function to look for modules in the virtual filesystem. The search patterns can be changed with lovr.filesystem.setRequirePath
, similar to package.path
.
Files
Operations for reading/writing files and querying their metadata.
lovr.filesystem.append | Append content to the end of a file. |
lovr.filesystem.createDirectory | Create a directory. |
lovr.filesystem.getDirectoryItems | Get a list of files in a directory. |
lovr.filesystem.getLastModified | Get the modification time of a file. |
lovr.filesystem.getSize | Get the size of a file. |
lovr.filesystem.isDirectory | Check whether a path is a directory. |
lovr.filesystem.isFile | Check whether a path is a file. |
lovr.filesystem.newBlob | Create a new Blob from a file. |
lovr.filesystem.newFile | Open a file, returning a `File` object. |
lovr.filesystem.read | Read a file. |
lovr.filesystem.remove | Remove a file or directory. |
lovr.filesystem.unwatch | Stop watching files. |
lovr.filesystem.watch | Start watching the filesystem for changes. |
lovr.filesystem.write | Write to a file. |
Virtual Filesystem
lovr.filesystem.getIdentity | Get the name of the save directory. |
lovr.filesystem.getRealDirectory | Get the absolute path to a file. |
lovr.filesystem.isFused | Check if the project is fused. |
lovr.filesystem.mount | Mount a directory or archive. |
lovr.filesystem.setIdentity | Set the name of the save directory. |
lovr.filesystem.unmount | Unmount a mounted archive. |
Paths
Useful system paths.
lovr.filesystem.getAppdataDirectory | Get the application data directory. |
lovr.filesystem.getExecutablePath | Get the path of the LÖVR executable. |
lovr.filesystem.getSaveDirectory | Get the location of the save directory. |
lovr.filesystem.getSource | Get the location of the project source. |
lovr.filesystem.getUserDirectory | Get the location of the user's home directory. |
lovr.filesystem.getWorkingDirectory | Get the current working directory. |
Lua
lovr.filesystem.getRequirePath | Get the require path. |
lovr.filesystem.load | Load a file as Lua code. |
lovr.filesystem.setRequirePath | Set the require path. |