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 .dll or .exe files is blocked.
  • By default, paths resolve under reframework/data/.

Path Tokens

Use these prefixes to select the base directory:

TokenResolves 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 as fs functions. nil as filepath passes through to stdin/stdout/stderr.
  • io.popen — Explicitly disabled (returns nil).
  • io.type, io.flush, io.close — Left as standard Lua.

require and package.loadlib

  • require is wrapped with the same path safety rules. package.path, package.cpath, and package.searchers are reset to pristine values before each require call.
  • package.loadlib is restricted to safe paths and only allows .dll extensions.

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.