-
Notifications
You must be signed in to change notification settings - Fork 0
New library: cfg
dounai2333 edited this page Jan 4, 2025
·
1 revision
The cfg library provides functions for reading .cfg file and format to Lua table.
Example .cfg file:
// Test cfg file named "test.cfg"
cl_showfps 1 // Show fps
cl_showpos "1" // Show pos
test_string1 foo
test_string2 "I'm a string with space character"
test_origin "1 2 3" // Vector
Read:
local cfg = dounai_lib.cfg.Parse("test.cfg")
print(IsValid(cfg)) -- Output: "true"
print(cfg:Length()) -- Output: "5"
print(cfg["cl_showfps"]) -- Output: "1"
print(cfg["cl_showpos"]) -- Output: "1"
print(cfg["test_string1"]) -- Output: "foo"
print(cfg["test_string2"]) -- Output: "I'm a string with space character"
print(cfg["test_origin"]) -- Output: "1.000000 2.000000 3.000000"dounai_lib.cfg.Parse(path, gamemode_string)Read and parse a .cfg file, format it properly and save to a table.
You can use IsValid(cfg) to check if the result is a valid cfg table. cfg:Length() will return the length of cfg table.
If gamemode_string is given, then the priority of file will be:
-- First priority, example: scripts/mod/zombie/cs_assault/test.cfg
scripts/mod/{gamemode_string}/(current map name)/{path}
-- Second priority, example: scripts/mod/zombie/test.cfg
scripts/mod/{gamemode_string}/{path}
If gamemode_string is empty or nil, then the priority of file will be:
-- First priority, directly read the file from given path.
test.cfg
-- Second priority, example: scripts/test.cfg
scripts/test.cfg
Return: table
path: string
gamemode_string: string