Skip to content

ax.util

Source: gamemode/framework/util/util_file.lua

Utility helpers used across the Parallax framework (printing, file handling, text utilities, etc.).

Section: file_utilities

Documented functions: 7

Functions


ax.util:BuildDataPath(key, options)

Build a data file path based on key and scope options.

Parameters

Name Type Description
key string The data key
options table\|nil Options table (scope, human)

Returns

  • string: The data file path relative to DATA

Usage

local path = ax.util:BuildDataPath("settings_player", { scope = "project" })

ax.util:DetectFileRealm(file)

Utility helpers used across the Parallax framework (printing, file handling, text utilities, etc.). File and JSON helpers. Detects the realm of a file based on its name.

Parameters

Name Type Description
file string Filename to inspect (may include path)

Returns

  • string: One of "client", "server", or "shared"

Usage

local realm = ax.util:DetectFileRealm("cl_init.lua") -- returns "client"

ax.util:EnsureDataDir(path)

Ensure parent directories exist for a given data path.

Parameters

Name Type Description
path string Data path to ensure directories for (e.g. "parallax/foo/bar/")

Usage

ax.util:EnsureDataDir("parallax/settings_player/")

ax.util:Include(path, realm)

Includes a Lua file, handling AddCSLuaFile/include based on realm.

Parameters

Name Type Description
path string Path to the Lua file to include (relative to gamemode)
realm string\|nil Optional realm hint: "client", "server", or "shared"

Returns

  • boolean: True if include/AddCSLuaFile was attempted

Usage

ax.util:Include("framework/util.lua")

ax.util:IncludeDirectory(directory, fromLua, toSkip, timeFilter)

Recursively includes all Lua files found under a directory.

Parameters

Name Type Description
directory string Directory path to include (relative to gamemode)
fromLua boolean\|nil Internal flag used when recursing from Lua
toSkip table\|nil Optional set of filenames or directory names to skip

Returns

  • boolean: True if directory processed

Usage

ax.util:IncludeDirectory("framework/libraries/")

ax.util:ReadJSON(path)

Read and parse a JSON file from DATA safely.

Parameters

Name Type Description
path string Path in DATA to read

Returns

  • table|nil: Parsed table or nil on error

Usage

local cfg = ax.util:ReadJSON("parallax/config.json")

ax.util:WriteJSON(path, tbl)

Write a table to a JSON file in DATA safely.

Parameters

Name Type Description
path string Path in DATA to write
tbl table Table to serialize

Returns

  • boolean: True on success

Usage

ax.util:WriteJSON("parallax/config.json", myTable)