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
modlib = setmetatable({
-- TODO bump on release
version = 94,
version = 95,
modname = minetest and minetest.get_current_modname(),
_RG = setmetatable({}, {
__index = function(_, index)

@ -1,11 +1,13 @@
-- 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
local _ENV = {}
setfenv(1, _ENV)
-- 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)
local tree = {}
for key, value in pairs(dict) do
@ -15,9 +17,18 @@ function build_tree(dict)
local index = tonumber(path[i]) or path[i]
subtree[index] = subtree[index] or {}
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
return tree
end
if minetest then