-
-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update lua FileSystem to use URI based parameters and allow opening o…
…f files and creation of directories Rather than passing a Root field we use a URI, with either a "data" or "user" scheme to indicate where they are working Add a MakeDirectory method Add a Open method that returns a lua io file interface Also add a redacted lua io interface. Add a FileSystem.lua with meta stubs for lint/hinting.
- Loading branch information
1 parent
c375375
commit 1cc5f3d
Showing
9 changed files
with
272 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
-- Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details | ||
-- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt | ||
|
||
-- This file implements type information about C++ classes for Lua static analysis | ||
-- This is used in FileSyestem.lua whcih then extends that. | ||
|
||
---@meta | ||
|
||
---@class FileSystem | ||
local FileSystem = {} | ||
|
||
---@param path string The directory to read the contents of. | ||
---@return string[] files A list of files as full paths from the root | ||
---@return string[] dirs A list of dirs as full paths from the root | ||
--- | ||
--- Example: | ||
--- > local files, dirs = FileSystem.ReadDirectory("user://savefiles") | ||
function FileSystem.ReadDirectory(path) end | ||
|
||
--- Join the passed arguments into a path, correctly handling separators and . | ||
--- and .. special dirs. | ||
--- | ||
---@param arg string[] A list of path elements to be joined | ||
---@return string The joined path elements | ||
function FileSystem.JoinPath( ... ) end | ||
|
||
---@param dir_name string The name of the folder to create | ||
---@return boolean Success | ||
function FileSystem.MakeDirectory( dir_name ) end | ||
|
||
--- Wrapper for our patched io.open that ensures files are opened inside the sandbox. | ||
--- Prefer using this to io.open | ||
--- | ||
--- Files in the user folder can be read or written to | ||
--- Files in the data folder are read only. | ||
--- | ||
--- | ||
--- | ||
--- Example: | ||
--- > f = FileSystem.Open( "user://my_file.txt", "w" ) | ||
--- > f:write( "file contents" ) | ||
--- > f:close() | ||
--- | ||
---@param filename string The name of the file to open, must start either user:// or data:// | ||
---@param mode string|nil The mode to open the file in, defaults to read only. Only user location files can be written | ||
---@return file A lua io file | ||
function FileSystem.Open( filename ) end | ||
|
||
return FileSystem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.