mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-29 18:53:44 +01:00
Lazy alias handling, remove testing code
This commit is contained in:
parent
cedfe1387b
commit
137e471262
27
init.lua
27
init.lua
@ -54,7 +54,7 @@ for _, file in pairs{
|
|||||||
"persistence",
|
"persistence",
|
||||||
"debug"
|
"debug"
|
||||||
} do
|
} do
|
||||||
modules[file] = true
|
modules[file] = file
|
||||||
end
|
end
|
||||||
if minetest then
|
if minetest then
|
||||||
for _, file in pairs{
|
for _, file in pairs{
|
||||||
@ -64,9 +64,12 @@ if minetest then
|
|||||||
-- deprecated
|
-- deprecated
|
||||||
"conf"
|
"conf"
|
||||||
} do
|
} do
|
||||||
modules[file] = true
|
modules[file] = file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
-- aliases
|
||||||
|
modules.string = "text"
|
||||||
|
modules.number = "math"
|
||||||
|
|
||||||
local parent_dir
|
local parent_dir
|
||||||
if not minetest then
|
if not minetest then
|
||||||
@ -104,25 +107,28 @@ modlib = setmetatable({
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
}, {
|
}, {
|
||||||
__index = function(self, module_name)
|
__index = function(self, module_name_or_alias)
|
||||||
if not modules[module_name] then
|
local module_name = modules[module_name_or_alias]
|
||||||
|
if not module_name then
|
||||||
-- module not available, return nil
|
-- module not available, return nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local environment = dofile(minetest
|
local environment
|
||||||
|
if module_name ~= module_name_or_alias then
|
||||||
|
-- alias handling
|
||||||
|
environment = self[module_name]
|
||||||
|
else
|
||||||
|
environment = dofile(minetest
|
||||||
and get_resource(self.modname, module_name .. ".lua")
|
and get_resource(self.modname, module_name .. ".lua")
|
||||||
or (parent_dir .. module_name .. ".lua"))
|
or (parent_dir .. module_name .. ".lua"))
|
||||||
self[module_name] = environment
|
end
|
||||||
|
self[module_name_or_alias] = environment
|
||||||
return environment
|
return environment
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
modlib.mod = minetest and dofile(get_resource(modlib.modname, "mod.lua"))
|
modlib.mod = minetest and dofile(get_resource(modlib.modname, "mod.lua"))
|
||||||
|
|
||||||
-- Aliases
|
|
||||||
modlib.string = modlib.text
|
|
||||||
modlib.number = modlib.math
|
|
||||||
|
|
||||||
if minetest then
|
if minetest then
|
||||||
modlib.conf.build_setting_tree()
|
modlib.conf.build_setting_tree()
|
||||||
modlib.mod.get_resource = get_resource
|
modlib.mod.get_resource = get_resource
|
||||||
@ -130,7 +136,6 @@ end
|
|||||||
|
|
||||||
_ml = modlib
|
_ml = modlib
|
||||||
|
|
||||||
modlib.mod.include"test.lua"
|
|
||||||
--[[
|
--[[
|
||||||
--modlib.mod.include"test.lua"
|
--modlib.mod.include"test.lua"
|
||||||
]]
|
]]
|
||||||
|
Loading…
Reference in New Issue
Block a user