File Loading System
cLib provides a smart file loading system that automatically handles client/server file inclusion based on file prefixes.
File Prefixes
| Prefix | Runs On | AddCSLuaFile | Include |
|---|---|---|---|
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:
| Parameter | Type | Description |
|---|---|---|
filename | string | File name with prefix |
directory | string | Directory path (must end with /) |
filter | string | Optional: "sh", "sv", or "cl" |
boolean success, boolean shouldPrintExample:
-- 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:
| Parameter | Type | Description |
|---|---|---|
directory | string | Directory path |
filter | string | Optional filter |
-- 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