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; absolute paths are rejected.
- Parent directory traversal (
..) is rejected. - Writing
.dllor.exefiles is blocked. - 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.package.path,package.cpath, andpackage.searchersare reset to pristine values before eachrequirecall.package.loadlibis restricted to safe paths and only allows.dllextensions.
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.