From 8cfe305ba55e517505fd5a2cee57a75235612cbf Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 5 May 2019 14:12:15 +1000 Subject: refactor: reorganise code in get_lua_version --- src/luarocks/cmd.lua | 17 ++++++++++------- 1 file 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) return flags["lua-version"] end local dirs = {} - if cfg.home_tree then - dirs[1] = dir.path(cfg.home_tree, ".luarocks") - end - table.insert(dirs, cfg.sysconfdir) + local next_i = 1 if flags["project-tree"] then - table.insert(dirs, 1, dir.path(flags["project-tree"], "..", ".luarocks")) + dirs[next_i] = dir.path(flags["project-tree"], "..", ".luarocks") + next_i = next_i + 1 + end + if cfg.home_tree then + dirs[next_i] = dir.path(cfg.home_tree, ".luarocks") + next_i = next_i + 1 end - for _, d in ipairs(dirs) do - local f = dir.path(d, "default-lua-version.lua") + dirs[next_i] = cfg.sysconfdir + for i=1, next_i do + local f = dir.path(dirs[i], "default-lua-version.lua") local mod, err = loadfile(f, "t") if mod then local pok, ver = pcall(mod) -- cgit v1.2.3-55-g6feb