diff --git a/plugin/ExtensionTree.lua b/lua/SpecSwitcher/ExtensionMap.lua similarity index 73% rename from plugin/ExtensionTree.lua rename to lua/SpecSwitcher/ExtensionMap.lua index 2051cb4..c4225e7 100644 --- a/plugin/ExtensionTree.lua +++ b/lua/SpecSwitcher/ExtensionMap.lua @@ -1,14 +1,13 @@ +local ExtMap = {} -ExtTree = {} - -function ExtTree:new (o) +function ExtMap:new (o) o = o or {} setmetatable(o, self) self.__index = self return o end -function ExtTree:add_single (in_ext, out_ext) +function ExtMap: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 @@ -26,7 +25,7 @@ function ExtTree:add_single (in_ext, out_ext) end end -function ExtTree:add_multiple (in_exts, out_exts) +function ExtMap:add (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) @@ -44,7 +43,7 @@ function ExtTree:add_multiple (in_exts, out_exts) end end -function ExtTree:print () +function ExtMap:print () base = "%s -> " for I in pairs(self) do local in_map = string.format(base, I) @@ -55,12 +54,4 @@ function ExtTree:print () 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() +return ExtMap