ExtTree = {} function ExtTree:new (o) o = o or {} setmetatable(o, self) self.__index = self return o end function ExtTree:add_single (in_ext, out_ext) if self[in_ext] ~= nil then if type(out_ext) == "table" then for _, out in ipairs(out_ext) do table.insert(self[in_ext], out) end else table.insert(self[in_ext], out_ext) end else if type(out_ext) == "table" then self[in_ext] = out_ext else self[in_ext] = {out_ext} end end end function ExtTree:add_multiple (in_exts, out_exts) if type(in_exts) == "table" then for _, in_ext in ipairs(in_exts) do self:add_single( in_ext, out_exts) end else self:add_single( in_exts, out_exts ) end if type(out_exts) == "table" then for _, out_ext in ipairs(out_exts) do self:add_single( out_ext, in_exts) end else self:add_single( out_exts, in_exts ) end end function ExtTree:print () base = "%s -> " for I in pairs(self) do local in_map = string.format(base, I) for _, O in ipairs(self[I]) do in_map = in_map .. O .. "," end print(in_map) end end p1 = ExtTree:new(nil) p1:add_multiple("h", {"c", "cpp", "cxx", "cc", "CC"}) p1:add_multiple("H", {"C", "CPP", "CXX", "CC"}) p1:add_multiple("hpp", {"cpp", "c"}) p1:add_multiple("HPP", {"CPP", "C"}) p1:add_multiple("ads", "adb") p1:print()