Difference between revisions of "love.filesystem (简体中文)"

m
m (类型)
 
(2 intermediate revisions by the same user not shown)
Line 45: Line 45:
 
被打开以进行读取操作的文件将先在 save 目录中查找,然后是 .love 档案 (遵照这个顺序)。 所以如果一个具有特定文件名 (和路径) 的文件同时存在于 .love 档案和 save 文件夹里,save 目录里那个会被优先读取。
 
被打开以进行读取操作的文件将先在 save 目录中查找,然后是 .love 档案 (遵照这个顺序)。 所以如果一个具有特定文件名 (和路径) 的文件同时存在于 .love 档案和 save 文件夹里,save 目录里那个会被优先读取。
  
 +
It is recommended to set your game's identity first in your [[Config Files|conf.lua]]. You can set it with [[love.filesystem.setIdentity]] as well.
 +
 +
{{notice|There's [https://bitbucket.org/MartinFelis/love-android-sdl2/issues/132 bug] in [[0.10.0]], up to [[0.10.2]] where any operation involving the game save directory (i.e. [[love.filesystem.write|writing]]) always fail in Android Marshmallow and later versions. The workaround is to enable [[Config_Files#externalstorage|externalstorage]] configuration.}}
 +
== 类型 ==
 +
最近一次更新:019/10/31
 +
追赶上当前英文页面进度:否
 +
{{#ask: [[Category:Types]] [[parent::love.filesystem (简体中文)]] [[Concept:Current]]
 +
| headers=hide
 +
| format=template
 +
| template=ListingFields
 +
| introtemplate=ListingIntro
 +
| outrotemplate=ListingOutro
 +
| ?Description
 +
| ?PrettySince
 +
| ?PrettyRemoved
 +
| ?PrettyDeprecated
 +
}}
 +
 +
== 函数 ==
 +
{{#ask: [[Category:Functions]] [[parent::love.filesystem]] [[Concept:Current]]
 +
| headers=hide
 +
| format=template
 +
| template=ListingFields
 +
| introtemplate=ListingIntro
 +
| outrotemplate=ListingOutro
 +
| ?Description
 +
| ?PrettySince
 +
| ?PrettyRemoved
 +
| ?PrettyDeprecated
 +
}}
 +
== 枚举变量 ==
 +
{{#ask: [[Category:Enums]] [[parent::love.filesystem]] [[Concept:Current]]
 +
| headers=hide
 +
| format=template
 +
| template=ListingFields
 +
| introtemplate=ListingIntro
 +
| outrotemplate=ListingOutro
 +
| ?Description
 +
| ?PrettySince
 +
| ?PrettyRemoved
 +
}}
 +
[[Category:Modules]]
 +
{{#set:Description=Provides an interface to the user's filesystem.}}
 
== 另见 ==
 
== 另见 ==
 
* [[parent::love (简体中文)]]
 
* [[parent::love (简体中文)]]

Latest revision as of 12:19, 31 October 2019

提供用户文件系统的接口。

此模块提供对以下特定位置的文件的访问:

  • .love 档案所在的根文件夹(或源目录)
  • 游戏 保存目录 的根文件夹。
  • 包含 游戏的.love 档案(或源目录)的文件夹,仅当 具体条件 满足。

每个在系统上的游戏都有一个可让文件通过 love.filesystem 被保存的目录。这是 唯一一个 love.filesystem 可以写文件的目录。这些目录通常可以在以下位置找到:

系统类型 路径 别的形式 注意
Windows XP C:\Documents and Settings\user\Application Data\LOVE\ %appdata%\LOVE\ When fused(当失败的时候?)储存目录会直接在Application Data下建立,而不是LOVE的子目录。
Windows Vista, 7, 8 and 10 C:\Users\user\AppData\Roaming\LOVE %appdata%\LOVE\ When fused(当失败的时候?)储存目录会直接在AppData下建立,而不是LOVE的子目录。
Mac /Users/user/Library/Application Support/LOVE/ - -
Linux $XDG_DATA_HOME/love/ ~/.local/share/love/ -
Android /data/user/0/org.love2d.android/files/save/ /data/data/org.love2d.android/files/save/ 在 Android 上有好几种储存地点。如果这两个路径不能用,你可以使用love.filesystem.getSaveDirectory()来获得储存路径。

被打开以进行写入或追加操作的文件总是在 save 目录中被创建。这对于其他那些涉及到文件系统写入的操作也有效,比如 mkdir。

被打开以进行读取操作的文件将先在 save 目录中查找,然后是 .love 档案 (遵照这个顺序)。 所以如果一个具有特定文件名 (和路径) 的文件同时存在于 .love 档案和 save 文件夹里,save 目录里那个会被优先读取。

It is recommended to set your game's identity first in your conf.lua. You can set it with love.filesystem.setIdentity as well.

O.png There's bug in 0.10.0, up to 0.10.2 where any operation involving the game save directory (i.e. writing) always fail in Android Marshmallow and later versions. The workaround is to enable externalstorage configuration.  


类型

最近一次更新:019/10/31 追赶上当前英文页面进度:否

DroppedFile (简体中文) 表示被拖拽到窗口的文件 Added since 0.10.0

函数

love.filesystem.append Append data to an existing file. Added since 0.9.0
love.filesystem.areSymlinksEnabled Gets whether love.filesystem follows symbolic links. Added since 0.9.2
love.filesystem.createDirectory Creates a directory. Added since 0.9.0
love.filesystem.enumerate Returns all the files and subdirectories in the directory. Added since 0.3.0 Removed in 0.9.0
love.filesystem.exists Check whether a file or directory exists. Deprecated in 11.0
love.filesystem.getAppdataDirectory Returns the application data directory (could be the same as getUserDirectory)
love.filesystem.getCRequirePath Gets the filesystem paths that will be searched for c libraries when require is called. Added since 11.0
love.filesystem.getDirectoryItems Returns all the files and subdirectories in the directory. Added since 0.9.0
love.filesystem.getIdentity Gets the write directory name for your game. Added since 0.9.0
love.filesystem.getInfo Gets information about the specified file or directory. Added since 11.0
love.filesystem.getLastModified Gets the last modification time of a file. Added since 0.7.1 Deprecated in 11.0
love.filesystem.getRealDirectory Gets the absolute path of the directory containing a filepath. Added since 0.9.2
love.filesystem.getRequirePath Gets the filesystem paths that will be searched when require is called. Added since 0.10.0
love.filesystem.getSaveDirectory Gets the full path to the designated save directory. Added since 0.5.0
love.filesystem.getSize Gets the size in bytes of a file. Added since 0.9.0 Deprecated in 11.0
love.filesystem.getSource Returns the full path to the .love file or directory. Added since 0.9.0
love.filesystem.getSourceBaseDirectory Returns the full path to the directory containing the .love file. Added since 0.9.0
love.filesystem.getUserDirectory Returns the path of the user's directory
love.filesystem.getWorkingDirectory Gets the current working directory. Added since 0.5.0
love.filesystem.init Initializes love.filesystem, will be called internally, so should not be used explicitly.
love.filesystem.isDirectory Check whether something is a directory. Deprecated in 11.0
love.filesystem.isFile Check whether something is a file. Deprecated in 11.0
love.filesystem.isFused Gets whether the game is in fused mode or not. Added since 0.9.0
love.filesystem.isSymlink Gets whether a filepath is actually a symbolic link. Added since 0.9.2 Deprecated in 11.0
love.filesystem.lines Iterate over the lines in a file. Added since 0.5.0
love.filesystem.load Loads a Lua file (but does not run it). Added since 0.5.0
love.filesystem.mkdir Creates a directory. Removed in 0.9.0
love.filesystem.mount Mounts a zip file or folder in the game's save directory for reading. Added since 0.9.0
love.filesystem.newFile Creates a new File object.
love.filesystem.newFileData Creates a new FileData object from a file on disk, or from a string in memory. Added since 0.7.0
love.filesystem.read Read the contents of a file.
love.filesystem.remove Removes a file (or directory).
love.filesystem.setCRequirePath Sets the filesystem paths that will be searched for c libraries when require is called. Added since 11.0
love.filesystem.setIdentity Sets the write directory for your game.
love.filesystem.setRequirePath Sets the filesystem paths that will be searched when require is called. Added since 0.10.0
love.filesystem.setSource Sets the source of the game, where the code is present. Used internally.
love.filesystem.setSymlinksEnabled Sets whether love.filesystem follows symbolic links. Added since 0.9.2
love.filesystem.unmount Unmounts a zip file or folder previously mounted with love.filesystem.mount. Added since 0.9.0
love.filesystem.write Write data to a file.

枚举变量

FileDecoder How to decode a given FileData. Added since 0.7.0 Removed in 11.0
FileMode The different modes you can open a File in.
FileType The type of a file. Added since 11.0

另见

Other Languages