diff options
author | daurnimator <quae@daurnimator.com> | 2019-05-05 14:12:15 +1000 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-05-06 11:43:12 -0300 |
commit | 8cfe305ba55e517505fd5a2cee57a75235612cbf (patch) | |
tree | c9e7ba3f37a4ec35f34dcd27d129a5562ede4c94 | |
parent | ea1e427c00753483fd5583140c8960b80bccc69b (diff) | |
download | luarocks-8cfe305ba55e517505fd5a2cee57a75235612cbf.tar.gz luarocks-8cfe305ba55e517505fd5a2cee57a75235612cbf.tar.bz2 luarocks-8cfe305ba55e517505fd5a2cee57a75235612cbf.zip |
refactor: reorganise code in get_lua_version
-rw-r--r-- | src/luarocks/cmd.lua | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index b2f036bf..284b1602 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua | |||
@@ -157,15 +157,18 @@ local function get_lua_version(flags) | |||
157 | return flags["lua-version"] | 157 | return flags["lua-version"] |
158 | end | 158 | end |
159 | local dirs = {} | 159 | local dirs = {} |
160 | if cfg.home_tree then | 160 | local next_i = 1 |
161 | dirs[1] = dir.path(cfg.home_tree, ".luarocks") | ||
162 | end | ||
163 | table.insert(dirs, cfg.sysconfdir) | ||
164 | if flags["project-tree"] then | 161 | if flags["project-tree"] then |
165 | table.insert(dirs, 1, dir.path(flags["project-tree"], "..", ".luarocks")) | 162 | dirs[next_i] = dir.path(flags["project-tree"], "..", ".luarocks") |
163 | next_i = next_i + 1 | ||
164 | end | ||
165 | if cfg.home_tree then | ||
166 | dirs[next_i] = dir.path(cfg.home_tree, ".luarocks") | ||
167 | next_i = next_i + 1 | ||
166 | end | 168 | end |
167 | for _, d in ipairs(dirs) do | 169 | dirs[next_i] = cfg.sysconfdir |
168 | local f = dir.path(d, "default-lua-version.lua") | 170 | for i=1, next_i do |
171 | local f = dir.path(dirs[i], "default-lua-version.lua") | ||
169 | local mod, err = loadfile(f, "t") | 172 | local mod, err = loadfile(f, "t") |
170 | if mod then | 173 | if mod then |
171 | local pok, ver = pcall(mod) | 174 | local pok, ver = pcall(mod) |