annotate share/lua/5.2/luarocks/dir.lua @ 12500:e48c08805365 draft default tip

<b_jonas> ` learn \'The password of the month is Cthulhuquagdonic Mothraquagdonic Narwhalicorn.\' # https://logs.esolangs.org/libera-esolangs/2024-04.html#lKE Infinite craft
author HackEso <hackeso@esolangs.org>
date Wed, 01 May 2024 06:39:10 +0000
parents d137f631bad5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1132
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
1
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
2 --- Generic utilities for handling pathnames.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
3 module("luarocks.dir", package.seeall)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
4
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
5 separator = "/"
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
6
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
7 --- Strip the path off a path+filename.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
8 -- @param pathname string: A path+name, such as "/a/b/c"
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
9 -- or "\a\b\c".
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
10 -- @return string: The filename without its path, such as "c".
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
11 function base_name(pathname)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
12 assert(type(pathname) == "string")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
13
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
14 local base = pathname:gsub("[/\\]*$", ""):match(".*[/\\]([^/\\]*)")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
15 return base or pathname
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
16 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
17
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
18 --- Strip the name off a path+filename.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
19 -- @param pathname string: A path+name, such as "/a/b/c".
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
20 -- @return string: The filename without its path, such as "/a/b/".
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
21 -- For entries such as "/a/b/", "/a/" is returned. If there are
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
22 -- no directory separators in input, "" is returned.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
23 function dir_name(pathname)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
24 assert(type(pathname) == "string")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
25
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
26 return (pathname:gsub("/*$", ""):match("(.*/)[^/]*")) or ""
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
27 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
28
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
29 --- Describe a path in a cross-platform way.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
30 -- Use this function to avoid platform-specific directory
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
31 -- separators in other modules. Removes trailing slashes from
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
32 -- each component given, to avoid repeated separators.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
33 -- Separators inside strings are kept, to handle URLs containing
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
34 -- protocols.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
35 -- @param ... strings representing directories
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
36 -- @return string: a string with a platform-specific representation
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
37 -- of the path.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
38 function path(...)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
39 local items = {...}
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
40 local i = 1
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
41 while items[i] do
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
42 items[i] = items[i]:gsub("(.+)/+$", "%1")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
43 if items[i] == "" then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
44 table.remove(items, i)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
45 else
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
46 i = i + 1
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
47 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
48 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
49 return (table.concat(items, "/"):gsub("(.+)/+$", "%1"))
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
50 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
51
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
52 --- Split protocol and path from an URL or local pathname.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
53 -- URLs should be in the "protocol://path" format.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
54 -- For local pathnames, "file" is returned as the protocol.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
55 -- @param url string: an URL or a local pathname.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
56 -- @return string, string: the protocol, and the pathname without the protocol.
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
57 function split_url(url)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
58 assert(type(url) == "string")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
59
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
60 local protocol, pathname = url:match("^([^:]*)://(.*)")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
61 if not protocol then
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
62 protocol = "file"
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
63 pathname = url
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
64 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
65 return protocol, pathname
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
66 end
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
67
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
68 function normalize(name)
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
69 return name:gsub("\\", "/"):gsub("(.)/*$", "%1")
d137f631bad5 <GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
HackBot
parents:
diff changeset
70 end