summaryrefslogtreecommitdiff
path: root/meta/3rd/love2d/library/love.filesystem.lua
blob: 5f6b1d18701ec5738d8b51fe95b6c9856f47eb3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
---@meta

---@class love.filesystem
love.filesystem = {}

---
---Append data to an existing file.
---
---@param name string # The name (and path) of the file.
---@param data string # The string data to append to the file.
---@param size number # How many bytes to write.
---@return boolean success # True if the operation was successful, or nil if there was an error.
---@return string errormsg # The error message on failure.
function love.filesystem.append(name, data, size) end

---
---Gets whether love.filesystem follows symbolic links.
---
---@return boolean enable # Whether love.filesystem follows symbolic links.
function love.filesystem.areSymlinksEnabled() end

---
---Recursively creates a directory.
---
---When called with 'a/b' it creates both 'a' and 'a/b', if they don't exist already.
---
---@param name string # The directory to create.
---@return boolean success # True if the directory was created, false if not.
function love.filesystem.createDirectory(name) end

---
---Returns the application data directory (could be the same as getUserDirectory)
---
---@return string path # The path of the application data directory
function love.filesystem.getAppdataDirectory() end

---
---Gets the filesystem paths that will be searched for c libraries when require is called.
---
---The paths string returned by this function is a sequence of path templates separated by semicolons. The argument passed to ''require'' will be inserted in place of any question mark ('?') character in each template (after the dot characters in the argument passed to ''require'' are replaced by directory separators.) Additionally, any occurrence of a double question mark ('??') will be replaced by the name passed to require and the default library extension for the platform.
---
---The paths are relative to the game's source and save directories, as well as any paths mounted with love.filesystem.mount.
---
---@return string paths # The paths that the ''require'' function will check for c libraries in love's filesystem.
function love.filesystem.getCRequirePath() end

---
---Returns a table with the names of files and subdirectories in the specified path. The table is not sorted in any way; the order is undefined.
---
---If the path passed to the function exists in the game and the save directory, it will list the files and directories from both places.
---
---@param dir string # The directory.
---@return table files # A sequence with the names of all files and subdirectories as strings.
function love.filesystem.getDirectoryItems(dir) end

---
---Gets the write directory name for your game. 
---
---Note that this only returns the name of the folder to store your files in, not the full path.
---
---@return string name # The identity that is used as write directory.
function love.filesystem.getIdentity() end

---
---Gets information about the specified file or directory.
---
---@param path string # The file or directory path to check.
---@param filtertype love.FileType # If supplied, this parameter causes getInfo to only return the info table if the item at the given path matches the specified file type.
---@return table info # A table containing information about the specified path, or nil if nothing exists at the path. The table contains the following fields:
function love.filesystem.getInfo(path, filtertype) end

---
---Gets the platform-specific absolute path of the directory containing a filepath.
---
---This can be used to determine whether a file is inside the save directory or the game's source .love.
---
---@param filepath string # The filepath to get the directory of.
---@return string realdir # The platform-specific full path of the directory containing the filepath.
function love.filesystem.getRealDirectory(filepath) end

---
---Gets the filesystem paths that will be searched when require is called.
---
---The paths string returned by this function is a sequence of path templates separated by semicolons. The argument passed to ''require'' will be inserted in place of any question mark ('?') character in each template (after the dot characters in the argument passed to ''require'' are replaced by directory separators.)
---
---The paths are relative to the game's source and save directories, as well as any paths mounted with love.filesystem.mount.
---
---@return string paths # The paths that the ''require'' function will check in love's filesystem.
function love.filesystem.getRequirePath() end

---
---Gets the full path to the designated save directory.
---
---This can be useful if you want to use the standard io library (or something else) to
---
---read or write in the save directory.
---
---@return string dir # The absolute path to the save directory.
function love.filesystem.getSaveDirectory() end

---
---Returns the full path to the the .love file or directory. If the game is fused to the LÖVE executable, then the executable is returned.
---
---@return string path # The full platform-dependent path of the .love file or directory.
function love.filesystem.getSource() end

---
---Returns the full path to the directory containing the .love file. If the game is fused to the LÖVE executable, then the directory containing the executable is returned.
---
---If love.filesystem.isFused is true, the path returned by this function can be passed to love.filesystem.mount, which will make the directory containing the main game (e.g. C:\Program Files\coolgame\) readable by love.filesystem.
---
---@return string path # The full platform-dependent path of the directory containing the .love file.
function love.filesystem.getSourceBaseDirectory() end

---
---Returns the path of the user's directory
---
---@return string path # The path of the user's directory
function love.filesystem.getUserDirectory() end

---
---Gets the current working directory.
---
---@return string cwd # The current working directory.
function love.filesystem.getWorkingDirectory() end

---
---Initializes love.filesystem, will be called internally, so should not be used explicitly.
---
---@param appname string # The name of the application binary, typically love.
function love.filesystem.init(appname) end

---
---Gets whether the game is in fused mode or not.
---
---If a game is in fused mode, its save directory will be directly in the Appdata directory instead of Appdata/LOVE/. The game will also be able to load C Lua dynamic libraries which are located in the save directory.
---
---A game is in fused mode if the source .love has been fused to the executable (see Game Distribution), or if '--fused' has been given as a command-line argument when starting the game.
---
---@return boolean fused # True if the game is in fused mode, false otherwise.
function love.filesystem.isFused() end

---
---Iterate over the lines in a file.
---
---@param name string # The name (and path) of the file
---@return function iterator # A function that iterates over all the lines in the file
function love.filesystem.lines(name) end

---
---Loads a Lua file (but does not run it).
---
---@param name string # The name (and path) of the file.
---@return function chunk # The loaded chunk.
---@return string errormsg # The error message if file could not be opened.
function love.filesystem.load(name) end

---
---Mounts a zip file or folder in the game's save directory for reading.
---
---It is also possible to mount love.filesystem.getSourceBaseDirectory if the game is in fused mode.
---
---@param archive string # The folder or zip file in the game's save directory to mount.
---@param mountpoint string # The new path the archive will be mounted to.
---@param appendToPath boolean # Whether the archive will be searched when reading a filepath before or after already-mounted archives. This includes the game's source and save directories.
---@return boolean success # True if the archive was successfully mounted, false otherwise.
function love.filesystem.mount(archive, mountpoint, appendToPath) end

---
---Creates a new File object. 
---
---It needs to be opened before it can be accessed.
---
---@param filename string # The filename of the file.
---@return love.File file # The new File object.
function love.filesystem.newFile(filename) end

---
---Creates a new FileData object.
---
---@param contents string # The contents of the file.
---@param name string # The name of the file.
---@return love.FileData data # Your new FileData.
function love.filesystem.newFileData(contents, name) end

---
---Read the contents of a file.
---
---@param name string # The name (and path) of the file.
---@param size number # How many bytes to read.
---@return string contents # The file contents.
---@return number size # How many bytes have been read.
---@return nil contents # returns nil as content.
---@return string error # returns an error message.
function love.filesystem.read(name, size) end

---
---Removes a file or empty directory.
---
---@param name string # The file or directory to remove.
---@return boolean success # True if the file/directory was removed, false otherwise.
function love.filesystem.remove(name) end

---
---Sets the filesystem paths that will be searched for c libraries when require is called.
---
---The paths string returned by this function is a sequence of path templates separated by semicolons. The argument passed to ''require'' will be inserted in place of any question mark ('?') character in each template (after the dot characters in the argument passed to ''require'' are replaced by directory separators.) Additionally, any occurrence of a double question mark ('??') will be replaced by the name passed to require and the default library extension for the platform.
---
---The paths are relative to the game's source and save directories, as well as any paths mounted with love.filesystem.mount.
---
---@param paths string # The paths that the ''require'' function will check in love's filesystem.
function love.filesystem.setCRequirePath(paths) end

---
---Sets the write directory for your game. 
---
---Note that you can only set the name of the folder to store your files in, not the location.
---
---@param name string # The new identity that will be used as write directory.
function love.filesystem.setIdentity(name) end

---
---Sets the filesystem paths that will be searched when require is called.
---
---The paths string given to this function is a sequence of path templates separated by semicolons. The argument passed to ''require'' will be inserted in place of any question mark ('?') character in each template (after the dot characters in the argument passed to ''require'' are replaced by directory separators.)
---
---The paths are relative to the game's source and save directories, as well as any paths mounted with love.filesystem.mount.
---
---@param paths string # The paths that the ''require'' function will check in love's filesystem.
function love.filesystem.setRequirePath(paths) end

---
---Sets the source of the game, where the code is present. This function can only be called once, and is normally automatically done by LÖVE.
---
---@param path string # Absolute path to the game's source folder.
function love.filesystem.setSource(path) end

---
---Sets whether love.filesystem follows symbolic links. It is enabled by default in version 0.10.0 and newer, and disabled by default in 0.9.2.
---
---@param enable boolean # Whether love.filesystem should follow symbolic links.
function love.filesystem.setSymlinksEnabled(enable) end

---
---Unmounts a zip file or folder previously mounted for reading with love.filesystem.mount.
---
---@param archive string # The folder or zip file in the game's save directory which is currently mounted.
---@return boolean success # True if the archive was successfully unmounted, false otherwise.
function love.filesystem.unmount(archive) end

---
---Write data to a file in the save directory. If the file existed already, it will be completely replaced by the new contents.
---
---@param name string # The name (and path) of the file.
---@param data string # The string data to write to the file.
---@param size number # How many bytes to write.
---@return boolean success # If the operation was successful.
---@return string message # Error message if operation was unsuccessful.
function love.filesystem.write(name, data, size) end

---@class love.DroppedFile: love.File, love.Object
local DroppedFile = {}

---@class love.File: love.Object
local File = {}

---
---Closes a File.
---
---@return boolean success # Whether closing was successful.
function File:close() end

---
---Flushes any buffered written data in the file to the disk.
---
---@return boolean success # Whether the file successfully flushed any buffered data to the disk.
---@return string err # The error string, if an error occurred and the file could not be flushed.
function File:flush() end

---
---Gets the buffer mode of a file.
---
---@return love.BufferMode mode # The current buffer mode of the file.
---@return number size # The maximum size in bytes of the file's buffer.
function File:getBuffer() end

---
---Gets the filename that the File object was created with. If the file object originated from the love.filedropped callback, the filename will be the full platform-dependent file path.
---
---@return string filename # The filename of the File.
function File:getFilename() end

---
---Gets the FileMode the file has been opened with.
---
---@return love.FileMode mode # The mode this file has been opened with.
function File:getMode() end

---
---Returns the file size.
---
---@return number size # The file size in bytes.
function File:getSize() end

---
---Gets whether end-of-file has been reached.
---
---@return boolean eof # Whether EOF has been reached.
function File:isEOF() end

---
---Gets whether the file is open.
---
---@return boolean open # True if the file is currently open, false otherwise.
function File:isOpen() end

---
---Iterate over all the lines in a file.
---
---@return function iterator # The iterator (can be used in for loops).
function File:lines() end

---
---Open the file for write, read or append.
---
---@param mode love.FileMode # The mode to open the file in.
---@return boolean ok # True on success, false otherwise.
---@return string err # The error string if an error occurred.
function File:open(mode) end

---
---Read a number of bytes from a file.
---
---@param bytes number # The number of bytes to read.
---@return string contents # The contents of the read bytes.
---@return number size # How many bytes have been read.
function File:read(bytes) end

---
---Seek to a position in a file
---
---@param pos number # The position to seek to
---@return boolean success # Whether the operation was successful
function File:seek(pos) end

---
---Sets the buffer mode for a file opened for writing or appending. Files with buffering enabled will not write data to the disk until the buffer size limit is reached, depending on the buffer mode.
---
---File:flush will force any buffered data to be written to the disk.
---
---@param mode love.BufferMode # The buffer mode to use.
---@param size number # The maximum size in bytes of the file's buffer.
---@return boolean success # Whether the buffer mode was successfully set.
---@return string errorstr # The error string, if the buffer mode could not be set and an error occurred.
function File:setBuffer(mode, size) end

---
---Returns the position in the file.
---
---@return number pos # The current position.
function File:tell() end

---
---Write data to a file.
---
---@param data string # The string data to write.
---@param size number # How many bytes to write.
---@return boolean success # Whether the operation was successful.
---@return string err # The error string if an error occurred.
function File:write(data, size) end

---@class love.FileData: love.Data, love.Object
local FileData = {}

---
---Gets the extension of the FileData.
---
---@return string ext # The extension of the file the FileData represents.
function FileData:getExtension() end

---
---Gets the filename of the FileData.
---
---@return string name # The name of the file the FileData represents.
function FileData:getFilename() end

---@class love.BufferMode
---@field none integer # No buffering. The result of write and append operations appears immediately.
---@field line integer # Line buffering. Write and append operations are buffered until a newline is output or the buffer size limit is reached.
---@field full integer # Full buffering. Write and append operations are always buffered until the buffer size limit is reached.

---@class love.FileDecoder
---@field file integer # The data is unencoded.
---@field base64 integer # The data is base64-encoded.

---@class love.FileMode
---@field r integer # Open a file for read.
---@field w integer # Open a file for write.
---@field a integer # Open a file for append.
---@field c integer # Do not open a file (represents a closed file.)

---@class love.FileType
---@field file integer # Regular file.
---@field directory integer # Directory.
---@field symlink integer # Symbolic link.
---@field other integer # Something completely different like a device.