2016-09-04 17:09:25 +02:00
|
|
|
modutils = {}
|
|
|
|
|
|
|
|
function modutils.get_depmod(modname)
|
|
|
|
-- Get dependency object (depmod)
|
|
|
|
|
|
|
|
-- Definition of returning object attributes
|
|
|
|
local depmod = {
|
2016-10-19 09:38:04 +02:00
|
|
|
modname, -- module name from get_depmod
|
2016-09-04 17:09:25 +02:00
|
|
|
deplist = {}, -- depends.txt parsed
|
2016-10-19 09:38:04 +02:00
|
|
|
}
|
2016-09-04 17:09:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- Definition of returning object methods
|
2016-10-19 09:38:04 +02:00
|
|
|
function depmod.check_depmod(checknode)
|
|
|
|
-- check if the node (checknode) is from dependent module
|
|
|
|
local delimpos = string.find(checknode, ":")
|
|
|
|
if delimpos then
|
|
|
|
local checkmodname = string.sub(checknode, 1, delimpos - 1)
|
|
|
|
for name, ref in pairs(depmod.deplist) do
|
|
|
|
if name == checkmodname then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2016-09-04 17:09:25 +02:00
|
|
|
|
|
|
|
-- Full returning object attributes
|
|
|
|
depmod.modname = modname
|
|
|
|
|
|
|
|
-- local variable definition
|
2016-10-19 09:38:04 +02:00
|
|
|
local depentry = {} -- Entry in deplist
|
2016-09-04 17:09:25 +02:00
|
|
|
local depmodname -- temp value
|
2016-10-19 09:38:04 +02:00
|
|
|
local modpath = minetest.get_modpath(modname)
|
|
|
|
if not modpath then
|
|
|
|
return nil -- module not found
|
|
|
|
end
|
|
|
|
local dependsfile = io.open(modpath.."/depends.txt")
|
2016-09-04 17:09:25 +02:00
|
|
|
if dependsfile then
|
|
|
|
for dependsline in dependsfile:lines() do
|
|
|
|
if string.sub(dependsline, -1) == "?" then
|
|
|
|
depentry.required = false
|
2016-10-19 09:38:04 +02:00
|
|
|
depmodname = string.sub(dependsline, 1, -2)
|
2016-09-04 17:09:25 +02:00
|
|
|
else
|
|
|
|
depentry.required = true
|
2016-10-19 09:38:04 +02:00
|
|
|
depmodname = dependsline
|
2016-09-04 17:09:25 +02:00
|
|
|
end
|
|
|
|
depmod.deplist[depmodname] = depentry
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return depmod
|
|
|
|
end
|