File Loading System

Core Systems Updated: Dec 10, 2025

File Loading System

cLib provides a smart file loading system that automatically handles client/server file inclusion based on file prefixes.

File Prefixes

PrefixRuns OnAddCSLuaFileInclude
sh_Both✅ Server✅ Both
sv_Server✅ Server
cl_Client✅ Server✅ Client

cLib.includeFile

Include a single file with automatic realm handling.

cLib.includeFile(filename, directory, filter)

Parameters:

ParameterTypeDescription
filenamestringFile name with prefix
directorystringDirectory path (must end with /)
filterstringOptional: "sh", "sv", or "cl"
Returns: boolean success, boolean shouldPrint

Example:

-- Include specific file
cLib.includeFile("sh_config.lua", "myaddon/")

-- Include from subdirectory
cLib.includeFile("sv_database.lua", "myaddon/core/")

-- With filter (only includes if matches)
cLib.includeFile("sh_utils.lua", "myaddon/", "sh")

cLib.includeDir

Include all Lua files in a directory recursively.

cLib.includeDir(directory, filter)

Parameters:

ParameterTypeDescription
directorystringDirectory path
filterstringOptional filter
Example:

-- Load ALL files in directory
cLib.includeDir("myaddon/")

-- Load only shared files
cLib.includeDir("myaddon/", "sh")

-- Load only client files
cLib.includeDir("myaddon/ui/", "cl")

-- Load only server files
cLib.includeDir("myaddon/server/", "sv")

Loading Order

Files are loaded in alphabetical order within each directory. To control order, prefix with numbers:

myaddon/
├── 01_sh_config.lua      # Loaded first
├── 02_sh_database.lua    # Loaded second
└── 99_sh_init.lua        # Loaded last