Comparison

core/configmanager.lua @ 13388:de6c1a170871

configmanager: Allow referencing previously-set options in the config file
author Matthew Wild <mwild1@gmail.com>
date Fri, 08 Dec 2023 13:36:51 +0000
parent 12972:ead41e25ebc0
child 13389:47d0d80da208
comparison
equal deleted inserted replaced
13387:e5ddae99faa8 13388:de6c1a170871
58 end 58 end
59 hostconfig[key] = value; 59 hostconfig[key] = value;
60 return true; 60 return true;
61 end 61 end
62 return false; 62 return false;
63 end
64
65 local function rawget_option(config_table, host, key)
66 if host and key then
67 local hostconfig = rawget(config_table, host);
68 if not hostconfig then
69 return nil;
70 end
71 return rawget(hostconfig, key);
72 end
63 end 73 end
64 74
65 function _M.set(host, key, value) 75 function _M.set(host, key, value)
66 return set(config, host, key, value); 76 return set(config, host, key, value);
67 end 77 end
117 Include = true, include = true, RunScript = true }, { 127 Include = true, include = true, RunScript = true }, {
118 __index = function (_, k) 128 __index = function (_, k)
119 if k:match("^ENV_") then 129 if k:match("^ENV_") then
120 return os.getenv(k:sub(5)); 130 return os.getenv(k:sub(5));
121 end 131 end
132 local val = rawget_option(config_table, env.__currenthost or "*", k);
133 if val ~= nil then
134 return val;
135 end
122 return rawget(_G, k); 136 return rawget(_G, k);
123 end, 137 end,
124 __newindex = function (_, k, v) 138 __newindex = function (_, k, v)
125 local host = env.__currenthost or "*"; 139 local host = env.__currenthost or "*";
126 local option_path = host.."/"..k; 140 local option_path = host.."/"..k;