From e3c6073f5912d3fd9d098783483a63bf39610fb3 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Sun, 21 Aug 2016 18:26:53 +0300 Subject: Refactor look_for_interpreter in install.bat Replace repeating code with loops. The only side effect should be that LUA_BINDIR now does not have trailing backslash when it's inferred. --- install.bat | 66 ++++++++++++++++++++----------------------------------------- 1 file changed, 21 insertions(+), 45 deletions(-) diff --git a/install.bat b/install.bat index cc4a5257..1bce4c53 100644 --- a/install.bat +++ b/install.bat @@ -287,56 +287,32 @@ end -- *********************************************************** -- Detect Lua -- *********************************************************** -local function look_for_interpreter (directory) +local function look_for_interpreter(directory) + local names = {S"lua$LUA_VERSION.exe", S"lua$LUA_SHORTV.exe", "lua.exe", "luajit.exe"} + local directories if vars.LUA_BINDIR then - -- if LUA_BINDIR is specified, it must be there, otherwise we fail - if exists( S"$LUA_BINDIR\\lua$LUA_VERSION.exe" ) then - vars.LUA_INTERPRETER = S"lua$LUA_VERSION.exe" - print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER") - return true - elseif exists( S"$LUA_BINDIR\\lua$LUA_SHORTV.exe" ) then - vars.LUA_INTERPRETER = S"lua$LUA_SHORTV.exe" - print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER") - return true - elseif exists(S"$LUA_BINDIR\\lua.exe") then - vars.LUA_INTERPRETER = "lua.exe" - print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER") - return true - elseif exists(S"$LUA_BINDIR\\luajit.exe") then - vars.LUA_INTERPRETER = "luajit.exe" - print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER") - return true - end - die(S"Lua executable lua.exe, luajit.exe, lua$LUA_SHORTV.exe or lua$LUA_VERSION.exe not found in $LUA_BINDIR") + -- If LUA_BINDIR is specified, look only in that directory. + directories = {vars.LUA_BINDIR} + else + -- Try candidate directory and its `bin` subdirectory. + directories = {directory, directory .. "\\bin"} end - for _, e in ipairs{ [[\]], [[\bin\]] } do - if exists(directory..e.."\\lua"..vars.LUA_VERSION..".exe") then - vars.LUA_INTERPRETER = S"lua$LUA_VERSION.exe" - vars.LUA_BINDIR = directory .. e - print(" Found ."..e..vars.LUA_INTERPRETER) - return true - - elseif exists(directory..e.."\\lua"..vars.LUA_SHORTV..".exe") then - vars.LUA_INTERPRETER = S"lua$LUA_SHORTV.exe" - vars.LUA_BINDIR = directory .. e - print(" Found ."..e..vars.LUA_INTERPRETER) - return true - - elseif exists(directory..e.."\\lua.exe") then - vars.LUA_INTERPRETER = "lua.exe" - vars.LUA_BINDIR = directory..e - print(" Found ."..e..vars.LUA_INTERPRETER) - return true - - elseif exists(directory..e.."\\luajit.exe") then - vars.LUA_INTERPRETER = "luajit.exe" - vars.LUA_BINDIR = directory..e - print(" Found ."..e..vars.LUA_INTERPRETER) - return true + for _, dir in ipairs(directories) do + for _, name in ipairs(names) do + local full_name = dir .. "\\" .. name + if exists(full_name) then + vars.LUA_INTERPRETER = name + vars.LUA_BINDIR = dir + print(" Found " .. full_name) + return true + end end end - --print(" No Lua interpreter found") + + if vars.LUA_BINDIR then + die(S"Lua executable lua.exe, luajit.exe, lua$LUA_SHORTV.exe or lua$LUA_VERSION.exe not found in $LUA_BINDIR") + end return false end -- cgit v1.2.3-55-g6feb