mirror of
https://github.com/appgurueu/modlib.git
synced 2025-02-18 09:03:46 +01:00
Update init, add tests
This commit is contained in:
20
init.lua
20
init.lua
@ -34,13 +34,17 @@ if _VERSION then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get modpath wrapper
|
-- TODO get rid of code duplication
|
||||||
local function get_resource(modname, resource)
|
local function get_resource(modname, resource)
|
||||||
|
if not resource then
|
||||||
|
resource = modname
|
||||||
|
modname = minetest.get_current_modname()
|
||||||
|
end
|
||||||
return minetest.get_modpath(modname) .. "/" .. resource
|
return minetest.get_modpath(modname) .. "/" .. resource
|
||||||
end
|
end
|
||||||
|
|
||||||
local function loadfile_exports(filename)
|
local function loadfile_exports(filename)
|
||||||
local env = setmetatable({}, {__index = _G, __call = _G})
|
local env = setmetatable({}, {__index = _G})
|
||||||
local file = assert(loadfile(filename))
|
local file = assert(loadfile(filename))
|
||||||
setfenv(file, env)
|
setfenv(file, env)
|
||||||
file()
|
file()
|
||||||
@ -60,13 +64,14 @@ local components = {
|
|||||||
player = {},
|
player = {},
|
||||||
table = {},
|
table = {},
|
||||||
text = {string = "local"},
|
text = {string = "local"},
|
||||||
threading = {}
|
threading = {},
|
||||||
|
vector = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
modlib = {}
|
modlib = {}
|
||||||
|
|
||||||
for component, additional in pairs(components) do
|
for component, additional in pairs(components) do
|
||||||
local comp = loadfile_exports(get_resource("modlib", 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, scope in pairs(additional) do
|
||||||
if scope == "global" then
|
if scope == "global" then
|
||||||
@ -81,7 +86,8 @@ modlib.conf.build_setting_tree()
|
|||||||
|
|
||||||
modlib.mod.loadfile_exports = loadfile_exports
|
modlib.mod.loadfile_exports = loadfile_exports
|
||||||
|
|
||||||
-- complete the string library (=metatable) with text helpers
|
|
||||||
modlib.table.complete(string, modlib.text)
|
|
||||||
|
|
||||||
_ml = modlib
|
_ml = modlib
|
||||||
|
|
||||||
|
--[[
|
||||||
|
--modlib.mod.include("test.lua")
|
||||||
|
]]
|
Reference in New Issue
Block a user