diff options
author | Peter Melnichenko <mpeterval@gmail.com> | 2016-08-22 20:14:43 +0300 |
---|---|---|
committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-08-23 08:52:16 +0300 |
commit | 4c837a0c953f0dd83485d65979893c3c773eb1ba (patch) | |
tree | 079cdf2323818325740bed10c4c533adee4092d7 | |
parent | b603e64b7e41e718157e98d1bcfa8673351b87f9 (diff) | |
download | luarocks-4c837a0c953f0dd83485d65979893c3c773eb1ba.tar.gz luarocks-4c837a0c953f0dd83485d65979893c3c773eb1ba.tar.bz2 luarocks-4c837a0c953f0dd83485d65979893c3c773eb1ba.zip |
install.bat: get rid of string splitting function
-rw-r--r-- | install.bat | 33 |
1 files changed, 3 insertions, 30 deletions
diff --git a/install.bat b/install.bat index bdde4413..cfa080e5 100644 --- a/install.bat +++ b/install.bat | |||
@@ -53,32 +53,6 @@ local function die(message) | |||
53 | os.exit(1) | 53 | os.exit(1) |
54 | end | 54 | end |
55 | 55 | ||
56 | local function split_string(str, delim, maxNb) | ||
57 | -- Eliminate bad cases... | ||
58 | if string.find(str, delim) == nil then | ||
59 | return { str } | ||
60 | end | ||
61 | if maxNb == nil or maxNb < 1 then | ||
62 | maxNb = 0 -- No limit | ||
63 | end | ||
64 | local result = {} | ||
65 | local pat = "(.-)" .. delim .. "()" | ||
66 | local nb = 0 | ||
67 | local lastPos | ||
68 | for part, pos in string.gmatch(str, pat) do | ||
69 | nb = nb + 1 | ||
70 | result[nb] = part | ||
71 | lastPos = pos | ||
72 | if nb == maxNb then break end | ||
73 | end | ||
74 | -- Handle the last field | ||
75 | if nb ~= maxNb then | ||
76 | result[nb + 1] = string.sub(str, lastPos) | ||
77 | end | ||
78 | return result | ||
79 | end | ||
80 | |||
81 | |||
82 | local function exec(cmd) | 56 | local function exec(cmd) |
83 | --print(cmd) | 57 | --print(cmd) |
84 | local status = os.execute("type NUL && "..cmd) | 58 | local status = os.execute("type NUL && "..cmd) |
@@ -567,16 +541,15 @@ local function get_possible_lua_directories() | |||
567 | 541 | ||
568 | -- No prefix given, so use PATH. | 542 | -- No prefix given, so use PATH. |
569 | local path = os.getenv("PATH") or "" | 543 | local path = os.getenv("PATH") or "" |
570 | path = path:gsub(";+", ";") -- Remove duplicates. | 544 | local directories = {} |
571 | local directories = split_string(path, ";") | 545 | for dir in path:gmatch("[^;]+") do |
572 | for i, dir in ipairs(directories) do | ||
573 | -- Remove trailing backslashes, but not from a drive letter like `C:\`. | 546 | -- Remove trailing backslashes, but not from a drive letter like `C:\`. |
574 | dir = dir:gsub("([^:])\\+$", "%1") | 547 | dir = dir:gsub("([^:])\\+$", "%1") |
575 | -- Remove trailing `bin` subdirectory, the searcher will check there anyway. | 548 | -- Remove trailing `bin` subdirectory, the searcher will check there anyway. |
576 | if dir:upper():match("[:\\]BIN$") then | 549 | if dir:upper():match("[:\\]BIN$") then |
577 | dir = dir:sub(1, -5) | 550 | dir = dir:sub(1, -5) |
578 | end | 551 | end |
579 | directories[i] = dir | 552 | table.insert(directories, dir) |
580 | end | 553 | end |
581 | -- Finally add some other default paths. | 554 | -- Finally add some other default paths. |
582 | table.insert(directories, [[c:\lua5.1.2]]) | 555 | table.insert(directories, [[c:\lua5.1.2]]) |