-
-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change to use a sandbox root element for opening io files in lua
Add annotations for FileSystem.lua
- Loading branch information
1 parent
172185e
commit 22f070b
Showing
5 changed files
with
148 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
---@class FileSystem : FileSystemBase | ||
local FileSystem = package.core["FileSystem"] | ||
|
||
--- 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 root string A FileSystemRoot constant. Can be either "DATA" or "USER" | ||
---@param filename string The name of the file to open, relative to the root | ||
---@param mode string|nil The mode to open the file in, defaults to read only | ||
---@return file A lua io file | ||
function FileSystem.Open( root, filename, mode ) | ||
if not mode then mode = "r" end | ||
|
||
return io.open( filename, mode, root ) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
-- 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 FileSystemBase | ||
local FileSystemBase = {} | ||
|
||
---@param root string A FileSystemRoot constant. Can be either "DATA" or "USER" | ||
---@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(root, path) | ||
function FileSystemBase.ReadDirectory(root, 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 FileSystemBase.JoinPath( ... ) end | ||
|
||
---@param dir_name string The name of the folder to create in the user directory | ||
---@return boolean Success | ||
function FileSystemBase.MakeUserDataDirectory( dir_name ) end | ||
|
||
return FileSystemBase |
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