Improve mod.get_resource

This commit is contained in:
Lars Mueller 2021-02-01 16:22:37 +01:00
parent 12826a7840
commit cfdf3cf67b

@ -34,12 +34,24 @@ if _VERSION then
end end
end end
local function get_resource(modname, resource) modlib = {
dir_delim = rawget(_G, "DIR_DELIM") or "/",
_RG = setmetatable({}, {
__index = function(_, index)
return rawget(_G, index)
end,
__newindex = function(_, index, value)
return rawset(_G, index, value)
end
})
}
local function get_resource(modname, resource, ...)
if not resource then if not resource then
resource = modname resource = modname
modname = minetest.get_current_modname() modname = minetest.get_current_modname()
end end
return minetest.get_modpath(modname) .. "/" .. resource return table.concat({minetest.get_modpath(modname), resource, ...}, modlib.dir_delim)
end end
local function loadfile_exports(filename) local function loadfile_exports(filename)
@ -50,15 +62,6 @@ local function loadfile_exports(filename)
return env return env
end end
modlib = {_RG = setmetatable({}, {
__index = function(_, index)
return rawget(_G, index)
end,
__newindex = function(_, index, value)
return rawset(_G, index, value)
end
})}
for _, component in ipairs{ for _, component in ipairs{
"mod", "mod",
"conf", "conf",