2016-10-19 23:28:55 +02:00
-- not modutils related, will be moved to a framework, if the utils framework will be developed :/
-- The envroot is accessable by global variable with module name as name (like if used in "carpets" mod, the modutils are at carpets.modutils available)
-- Different per module environment root allow the use of diffent versions of the same tool in different mods
2016-09-04 17:09:25 +02:00
2016-10-19 23:28:55 +02:00
local currentmod = minetest.get_current_modname ( )
local envroot = nil
2016-09-04 17:09:25 +02:00
2016-10-19 23:28:55 +02:00
if not currentmod or currentmod == " " then --not minetest or something hacky
envroot = _G --fallback for hacky calls, populate global
else
if not _G [ currentmod ] then
_G [ currentmod ] = { }
end
envroot = _G [ currentmod ]
end
-- framework stuff done. -- Now the tool
2016-09-04 17:09:25 +02:00
2016-10-19 23:28:55 +02:00
envroot.modutils = { }
2016-09-04 17:09:25 +02:00
-- Definition of returning object methods
2016-10-19 23:28:55 +02:00
local _check_depmod = function ( this , 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 ( this.deplist ) do
if name == checkmodname then
return true
2016-10-19 09:38:04 +02:00
end
end
2016-10-19 23:28:55 +02:00
return false
2016-10-19 09:38:04 +02:00
end
2016-10-19 23:28:55 +02:00
end
2016-09-04 17:09:25 +02:00
2016-10-19 23:28:55 +02:00
function envroot . modutils . get_depmod ( modname )
2016-09-04 17:09:25 +02:00
2016-10-19 23:28:55 +02:00
-- Definition of returning object attributes
local this = { }
this.modname = modname
this.deplist = { } -- depends.txt parsed
this.check_depmod = _check_depmod -- method
-- get module path
2016-10-19 09:38:04 +02:00
local modpath = minetest.get_modpath ( modname )
if not modpath then
return nil -- module not found
end
2016-10-19 23:28:55 +02:00
-- read the depends file
2016-10-19 09:38:04 +02:00
local dependsfile = io.open ( modpath .. " /depends.txt " )
2016-10-19 23:28:55 +02:00
if not dependsfile then
return nil
end
-- parse the depends file
for dependsline in dependsfile : lines ( ) do
local depentry = { } -- Entry in deplist
local depmodname
if string.sub ( dependsline , - 1 ) == " ? " then
depentry.required = false
depmodname = string.sub ( dependsline , 1 , - 2 )
else
depentry.required = true
depmodname = dependsline
2016-09-04 17:09:25 +02:00
end
2016-10-19 23:28:55 +02:00
this.deplist [ depmodname ] = depentry
2016-09-04 17:09:25 +02:00
end
2016-10-19 23:28:55 +02:00
return this
2016-09-04 17:09:25 +02:00
end