Init cleanup

This commit is contained in:
Lars Mueller 2020-12-21 18:23:30 +01:00
parent 847bca6f69
commit 27b2de0367
2 changed files with 6 additions and 19 deletions

@ -36,7 +36,6 @@ if _VERSION then
end end
end end
-- TODO get rid of code duplication
local function get_resource(modname, resource) local function get_resource(modname, resource)
if not resource then if not resource then
resource = modname resource = modname
@ -62,30 +61,27 @@ local components = {
func = {}, func = {},
log = {}, log = {},
minetest = {}, minetest = {},
math = {number = "local"}, math = {"number"},
player = {}, player = {},
table = {}, table = {},
text = {string = "local"}, text = {"string"},
vector = {}, vector = {},
trie = {} trie = {}
} }
modlib = {} modlib = {}
for component, additional in pairs(components) do for component, aliases in pairs(components) do
local comp = loadfile_exports(get_resource(component .. ".lua")) local comp = loadfile_exports(get_resource(component .. ".lua"))
modlib[component] = comp modlib[component] = comp
for alias, scope in pairs(additional) do for _, alias in pairs(aliases) do
if scope == "global" then modlib[alias] = comp
_G[alias] = comp
else
modlib[alias] = comp
end
end end
end end
modlib.conf.build_setting_tree() modlib.conf.build_setting_tree()
modlib.mod.get_resource = get_resource
modlib.mod.loadfile_exports = loadfile_exports modlib.mod.loadfile_exports = loadfile_exports
_ml = modlib _ml = modlib

@ -1,12 +1,3 @@
-- get modpath wrapper
function get_resource(modname, resource)
if not resource then
resource = modname
modname = minetest.get_current_modname()
end
return minetest.get_modpath(modname) .. "/" .. resource
end
-- get resource + dofile -- get resource + dofile
function include(modname, file) function include(modname, file)
if not file then if not file then