diff --git a/init.lua b/init.lua index eb60717..44f8613 100644 --- a/init.lua +++ b/init.lua @@ -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) diff --git a/minetest/conf.lua b/minetest/conf.lua index a9315e4..e673dbd 100644 --- a/minetest/conf.lua +++ b/minetest/conf.lua @@ -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,8 +17,17 @@ 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 - subtree[path[#path]] = value end return tree end @@ -303,4 +314,4 @@ function check_constraints(value, constraints) end -- Export environment -return _ENV \ No newline at end of file +return _ENV