end
-- use ipairs to keep the list entries ordered
for _,path in ipairs(cf_path) do
- local c = {}
- c.config = function(x)
- c.data = x
- end
+ local data = nil
+
e2lib.logf(4, "reading global config file: %s", path)
local rc = e2lib.exists(path)
if rc then
e2lib.logf(3, "using global config file: %s", path)
- rc, re = e2lib.dofile2(path, c, true)
+ rc, re = e2lib.dofile2(path,
+ { config = function(x) data = x end })
if not rc then
return false, re
end
- if not c.data then
+ if not data then
return false, err.new("invalid configuration")
end
- rc, re = verify_global_config(c.data)
+ rc, re = verify_global_config(data)
if not rc then
return false, re
end
- get_global_config_cache = strict.lock(c.data)
+ get_global_config_cache = strict.lock(data)
return get_global_config_cache
else
e2lib.logf(4, "global config file does not exist: %s", path)
e2lib.logf(3, "reading extension file: %s", extension_config)
- local c = {}
- c.extensions = function(x)
- c.data = x
- end
- rc, re = e2lib.dofile2(extension_config, c, true)
+ local data = nil
+ rc, re = e2lib.dofile2(extension_config,
+ { extensions = function(x) data = x end })
if not rc then
return false, e:cat(re)
end
- if not c.data then
+ if not data then
return false, e:append("invalid extension configuration")
end
- return c.data
+ return data
end
--- Successively returns the file names in the directory.
--- Executes Lua code loaded from path.
--@param path Filename to load lua code from (string).
--@param gtable Environment (table) that is used instead of the global _G.
---@param allownewdefs Boolean indicating whether new variables may be defined
--- and undefined ones read.
+-- If gtable has no metatable, the default is to reject
+-- __index and __newindex access.
--@return True on success, false on error.
--@return Error object on failure.
-function e2lib.dofile2(path, gtable, allownewdefs)
+function e2lib.dofile2(path, gtable)
local e = err.new("error loading config file: %s", path)
local chunk, msg = loadfile(path)
if not chunk then
return false, e:cat(msg)
end
+ --for k,v in pairs(gtable) do
+ -- e2lib.logf(1, "[%s] = %s", tostring(k), tostring(v))
+ --end
+
local function checkread(t, k)
local x = rawget(t, k)
if x then
path, tostring(k), tostring(v)), 0)
end
- if not allownewdefs then
+ if not getmetatable(gtable) then
setmetatable(gtable, { __newindex = checkwrite, __index = checkread })
end
dest[index] = table
end
- local rc, re = e2lib.dofile2(path, { [var] = func, env = info.env, string=string }, false)
+ local rc, re = e2lib.dofile2(path, { [var] = func, env = info.env, string=string })
if not rc then
return false, e:cat(re)
end
local g = {} -- compose the environment for the config file
g.env = info.env -- env
g.string = string -- string
- for _,type in ipairs(types) do
- g[type] = f[type] -- and some config functions
+ for _,typ in ipairs(types) do
+ g[typ] = f[typ] -- and some config functions
end
- rc, re = e2lib.dofile2(path, g, true)
+ rc, re = e2lib.dofile2(path, g)
if not rc then
return false, e:cat(re)
end
table.insert(info.env_files, file)
local path = e2lib.join(info.root, file)
- local g = {} -- compose the environment for the config file
- g.e2env = info.env -- env as built up so far
- g.string = string -- string
- g.env = mergeenv
- rc, re = e2lib.dofile2(path, g, true)
+ local g = {
+ e2env = info.env,
+ string = string,
+ env = mergeenv,
+ }
+ rc, re = e2lib.dofile2(path, g)
if not rc then
return false, e:cat(re)
end