Turn conf.build_tree error into warning

This commit is contained in:
Lars Mueller 2022-06-01 11:31:15 +02:00
parent 7989f40615
commit b974113fa9
2 changed files with 15 additions and 4 deletions

@ -119,7 +119,7 @@ end
local rawget, rawset = rawget, rawset local rawget, rawset = rawget, rawset
modlib = setmetatable({ modlib = setmetatable({
-- TODO bump on release -- TODO bump on release
version = 94, version = 95,
modname = minetest and minetest.get_current_modname(), modname = minetest and minetest.get_current_modname(),
_RG = setmetatable({}, { _RG = setmetatable({}, {
__index = function(_, index) __index = function(_, index)

@ -1,11 +1,13 @@
-- Localize globals -- Localize globals
local assert, dump, error, ipairs, minetest, modlib, pairs, pcall, table, tonumber, type = assert, dump, error, ipairs, minetest, modlib, pairs, pcall, table, tonumber, type local assert, dump, error, ipairs, minetest, modlib, pairs, pcall, table, tonumber, type, unpack = assert, dump, error, ipairs, minetest, modlib, pairs, pcall, table, tonumber, type, unpack
-- Set environment -- Set environment
local _ENV = {} local _ENV = {}
setfenv(1, _ENV) setfenv(1, _ENV)
-- not deprecated -- not deprecated
-- TODO find a better way to deal with settings used as both parent & leaf, ideally preserving the data of both (store in boolean field?)
local warn_parent_leaf = "modlib.minetest.conf.build_tree: setting %s used both as parent setting and as leaf, ignoring children"
function build_tree(dict) function build_tree(dict)
local tree = {} local tree = {}
for key, value in pairs(dict) do for key, value in pairs(dict) do
@ -15,8 +17,17 @@ function build_tree(dict)
local index = tonumber(path[i]) or path[i] local index = tonumber(path[i]) or path[i]
subtree[index] = subtree[index] or {} subtree[index] = subtree[index] or {}
subtree = subtree[index] subtree = subtree[index]
if type(subtree) ~= "table" then
minetest.log("warning", warn_parent_leaf:format(table.concat({unpack(path, 1, i)}, ".")))
break
end
end
if type(subtree) == "table" then
if type(subtree[path[#path]]) == "table" then
minetest.log("warning", warn_parent_leaf:format(key))
end
subtree[path[#path]] = value
end end
subtree[path[#path]] = value
end end
return tree return tree
end end