-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.lua
More file actions
35 lines (27 loc) · 814 Bytes
/
config.lua
File metadata and controls
35 lines (27 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
-- Configuration Loader with Defaults
local json = require('json') -- JSON library for decoding
local Config = {}
-- Default configuration values
Config.defaults = {
host = 'localhost',
port = 8080,
timeout = 30,
use_ssl = false
}
-- Function to load configuration from a file
function Config.load(configFile)
local file, err = io.open(configFile, 'r')
if err then
print('Error loading config file: ' .. err)
return Config.defaults -- return defaults on error
end
local content = file:read('*a')
file:close()
local configFromFile = json.decode(content)
-- Merge file config with defaults
for key, value in pairs(Config.defaults) do
configFromFile[key] = configFromFile[key] or value
end
return configFromFile
end
return Config