From 384dbb964a3420b39e6b5168b18f6f469dadaf8f Mon Sep 17 00:00:00 2001 From: Alexander Weber Date: Thu, 9 Mar 2017 00:39:07 +0100 Subject: [PATCH] modutils updated --- modutils.lua | 65 ++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/modutils.lua b/modutils.lua index 3f667dc..94ca4dd 100644 --- a/modutils.lua +++ b/modutils.lua @@ -1,6 +1,5 @@ local modutils = {} --- class methods function modutils.get_modname_by_itemname(itemname) local def = minetest.registered_items[itemname] if def then @@ -13,40 +12,36 @@ function modutils.get_modname_by_itemname(itemname) return nil end end - -end - --- object methods -local function check_depend(this, modname, deptype) - local depends = this.depends - if depends[modname] then - if not deptype then --"required" or "optional" only - return true - else - return (depends[modname] == deptype) - end - else - return false - end -end - -local function check_depend_by_itemname(this, itemname, deptype) - local modname = modutils.get_modname_by_itemname(itemname) - if modname then - return this:check_depend(modname, deptype) - else - return false - end end function modutils.get_depend_checker(modname) - -- Definition of returning object attributes - local this = { } - this.modname = modname - this.depends = {} -- depends.txt parsed - this.check_depend = check_depend - this.check_depend_by_itemname = check_depend_by_itemname + local self = { + modname = modname, + depends = {} -- depends.txt parsed + } + -- Check if dependency exists to mod modname + function self:check_depend(modname, deptype) + if self.depends[modname] then + if not deptype then --"required" or "optional" only + return true + else + return (self.depends[modname] == deptype) + end + else + return false + end + end + + --Check if dependency exists to item origin mod + function self:check_depend_by_itemname(itemname, deptype) + local modname = modutils.get_modname_by_itemname(itemname) + if modname then + return self:check_depend(modname, deptype) + else + return false + end + end -- get module path local modpath = minetest.get_modpath(modname) @@ -64,13 +59,13 @@ function modutils.get_depend_checker(modname) for line in dependsfile:lines() do if line:sub(-1) == "?" then line = line:sub(1, -2) - this.depends[line] = "optional" + self.depends[line] = "optional" else - this.depends[line] = "required" + self.depends[line] = "required" end end - - return this + dependsfile:close() + return self end return modutils