aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luarocks/core/cfg.lua19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua
index 48aff4d8..0c79fc63 100644
--- a/src/luarocks/core/cfg.lua
+++ b/src/luarocks/core/cfg.lua
@@ -504,6 +504,19 @@ local function use_defaults(cfg, defaults)
504 end 504 end
505end 505end
506 506
507local function get_first_arg()
508 if not arg then
509 return
510 end
511 local first_arg = arg[0]
512 local i = -1
513 while arg[i] do
514 first_arg = arg[i]
515 i = i -1
516 end
517 return first_arg
518end
519
507-------------------------------------------------------------------------------- 520--------------------------------------------------------------------------------
508 521
509local cfg = {} 522local cfg = {}
@@ -547,13 +560,15 @@ function cfg.init(detected, warning)
547 end 560 end
548 561
549 -- Use detected values as defaults, overridable via config files or CLI args 562 -- Use detected values as defaults, overridable via config files or CLI args
563
564 local first_arg = get_first_arg()
550 565
551 cfg.lua_version = detected.lua_version or hardcoded.LUA_VERSION or _VERSION:sub(5) 566 cfg.lua_version = detected.lua_version or hardcoded.LUA_VERSION or _VERSION:sub(5)
552 cfg.lua_interpreter = detected.lua_interpreter or hardcoded.LUA_INTERPRETER or (arg and arg[-1] and arg[-1]:gsub(".*[\\/]", "")) or (is_windows and "lua.exe" or "lua") 567 cfg.lua_interpreter = detected.lua_interpreter or hardcoded.LUA_INTERPRETER or (first_arg and first_arg:gsub(".*[\\/]", "")) or (is_windows and "lua.exe" or "lua")
553 cfg.project_dir = (not hardcoded.FORCE_CONFIG) and detected.project_dir 568 cfg.project_dir = (not hardcoded.FORCE_CONFIG) and detected.project_dir
554 569
555 do 570 do
556 local lua_bindir = detected.lua_bindir or hardcoded.LUA_BINDIR or (arg and arg[-1] and arg[-1]:gsub("[\\/][^\\/]+$", "")) 571 local lua_bindir = detected.lua_bindir or hardcoded.LUA_BINDIR or (first_arg and first_arg:gsub("[\\/][^\\/]+$", ""))
557 local lua_dir = detected.lua_dir or hardcoded.LUA_DIR or (lua_bindir and lua_bindir:gsub("[\\/]bin$", "")) 572 local lua_dir = detected.lua_dir or hardcoded.LUA_DIR or (lua_bindir and lua_bindir:gsub("[\\/]bin$", ""))
558 cfg.variables = { 573 cfg.variables = {
559 LUA_DIR = lua_dir, 574 LUA_DIR = lua_dir,