fs
This is the filesystem API. REFramework restricts scripts from unrestricted access to a user's system. All file APIs focus on safe subdirectories.
In newer builds of REFramework, the io API is supported with safety wrapping. io.popen is explicitly disabled (returns nil).
Path Safety Rules
All file APIs (fs.read, fs.write, fs.glob, io.open, io.lines, io.input, io.output, require, package.loadlib) enforce the following rules:
- All paths are relative. A path with a drive or a root raises an error:
C:\foo, but also\foo,/fooandC:foo. - Parent directory traversal (
..) is rejected. fsandiofunctions refuse.dlland.exefiles, so a script can't write one. The check uses the name Windows gives the file, which drops trailing dots and spaces, so a name likex.dll.is refused too.fsandiofunctions andpackage.loadlibreject paths that contain a NUL character.- By default, paths resolve under
reframework/data/.
Path Tokens
Use these prefixes to select the base directory:
| Token | Resolves to |
|---|---|
| (none) | reframework/data/ in the persistent directory |
$natives/ | natives/ directory relative to the REFramework DLL |
$autorun/ | reframework/autorun/ in the persistent directory |
io Library Safety Wrapping
The standard Lua io library is available but wrapped with path safety:
io.open,io.lines,io.input,io.output— All wrapped with the same path safety rules asfsfunctions.nilas filepath passes through to stdin/stdout/stderr.io.popen— Explicitly disabled (returnsnil).io.type,io.flush,io.close— Left as standard Lua.
require and package.loadlib
requireis wrapped with the same path safety rules: a module name containing..or starting with a drive or a root raises an error.package.path,package.cpath, andpackage.searchersare reset to pristine values before eachrequirecall.package.loadlib(path, funcname)is restricted to safe paths and only allows.dllextensions. The DLL is loaded from the resolved path, by default insidereframework/data/. It is not looked up by name in the game directory, the system directories orPATH. On failure it returnsnilplus an error message, like Lua's ownpackage.loadlib.- Both only load a native library from a file that is a
.dllunder its real name on disk. A file with another name that is reached through its 8.3 short name (X~1.DLL) is refused.
For a complete list of available Lua standard libraries and disabled functions, see Lua Standard Libraries.
Methods
fs.glob(filter, modifier)
Returns a table of file paths that match the filter. filter should be a regex string for the files you wish to match.
modifier is optional. Supports $natives and $autorun to select the base directory.
Example
-- Get my mods JSON files.
local json_files = fs.glob([[my-cool-mod\\.*json]])
-- Iterate over them.
for k, v in ipairs(json_files) do
-- v will be something like `my-cool-mod\config-file-1.json`
end
fs.read(filename)
Reads filename and returns the data as a string.
fs.write(filename, data)
Writes data to filename. data is a string.