diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-08-01 17:31:14 +0300 |
---|---|---|
committer | V1K1NGbg <victor@ilchev.com> | 2024-08-05 20:51:31 +0300 |
commit | ee82681346814fc20ccca9f1e397206ea7538465 (patch) | |
tree | 45aae9bed6138992dbe1035a6618c8b9cbe4e28f | |
parent | ee55c132b3415b1cd6993b6cf80a7c03a1090651 (diff) | |
download | luarocks-ee82681346814fc20ccca9f1e397206ea7538465.tar.gz luarocks-ee82681346814fc20ccca9f1e397206ea7538465.tar.bz2 luarocks-ee82681346814fc20ccca9f1e397206ea7538465.zip |
fun completed
-rw-r--r-- | src/luarocks/fetch/cvs.tl | 2 | ||||
-rw-r--r-- | src/luarocks/fun-original.lua | 143 | ||||
-rw-r--r-- | src/luarocks/fun.lua | 37 | ||||
-rw-r--r-- | src/luarocks/fun.tl | 26 | ||||
-rw-r--r-- | src/luarocks/type_check.tl | 2 |
5 files changed, 179 insertions, 31 deletions
diff --git a/src/luarocks/fetch/cvs.tl b/src/luarocks/fetch/cvs.tl index 1d874daf..60f55957 100644 --- a/src/luarocks/fetch/cvs.tl +++ b/src/luarocks/fetch/cvs.tl | |||
@@ -17,7 +17,7 @@ local type Rockspec = cfg.Rockspec | |||
17 | -- @return (string, string) or (nil, string): The absolute pathname of | 17 | -- @return (string, string) or (nil, string): The absolute pathname of |
18 | -- the fetched source tarball and the temporary directory created to | 18 | -- the fetched source tarball and the temporary directory created to |
19 | -- store it; or nil and an error message. | 19 | -- store it; or nil and an error message. |
20 | function cvs.get_sources(rockspec: Rockspec, extract, dest_dir?: string): string, string --? extract not needed | 20 | function cvs.get_sources(rockspec: Rockspec, extract: boolean, dest_dir?: string): string, string --? extract not needed |
21 | local cvs_cmd = rockspec.variables.CVS | 21 | local cvs_cmd = rockspec.variables.CVS |
22 | local ok, err_msg = fs.is_tool_available(cvs_cmd, "CVS") | 22 | local ok, err_msg = fs.is_tool_available(cvs_cmd, "CVS") |
23 | if not ok then | 23 | if not ok then |
diff --git a/src/luarocks/fun-original.lua b/src/luarocks/fun-original.lua new file mode 100644 index 00000000..80bf7c20 --- /dev/null +++ b/src/luarocks/fun-original.lua | |||
@@ -0,0 +1,143 @@ | |||
1 | |||
2 | --- A set of basic functional utilities | ||
3 | local fun = {} | ||
4 | |||
5 | local unpack = table.unpack or unpack | ||
6 | |||
7 | function fun.concat(xs, ys) | ||
8 | local rs = {} | ||
9 | local n = #xs | ||
10 | for i = 1, n do | ||
11 | rs[i] = xs[i] | ||
12 | end | ||
13 | for i = 1, #ys do | ||
14 | rs[i + n] = ys[i] | ||
15 | end | ||
16 | return rs | ||
17 | end | ||
18 | |||
19 | function fun.contains(xs, v) | ||
20 | for _, x in ipairs(xs) do | ||
21 | if v == x then | ||
22 | return true | ||
23 | end | ||
24 | end | ||
25 | return false | ||
26 | end | ||
27 | |||
28 | function fun.map(xs, f) | ||
29 | local rs = {} | ||
30 | for i = 1, #xs do | ||
31 | rs[i] = f(xs[i]) | ||
32 | end | ||
33 | return rs | ||
34 | end | ||
35 | |||
36 | function fun.filter(xs, f) | ||
37 | local rs = {} | ||
38 | for i = 1, #xs do | ||
39 | local v = xs[i] | ||
40 | if f(v) then | ||
41 | rs[#rs+1] = v | ||
42 | end | ||
43 | end | ||
44 | return rs | ||
45 | end | ||
46 | |||
47 | function fun.traverse(t, f) | ||
48 | return fun.map(t, function(x) | ||
49 | return type(x) == "table" and fun.traverse(x, f) or f(x) | ||
50 | end) | ||
51 | end | ||
52 | |||
53 | function fun.reverse_in(t) | ||
54 | for i = 1, math.floor(#t/2) do | ||
55 | local m, n = i, #t - i + 1 | ||
56 | local a, b = t[m], t[n] | ||
57 | t[m] = b | ||
58 | t[n] = a | ||
59 | end | ||
60 | return t | ||
61 | end | ||
62 | |||
63 | function fun.sort_in(t, f) | ||
64 | table.sort(t, f) | ||
65 | return t | ||
66 | end | ||
67 | |||
68 | function fun.flip(f) | ||
69 | return function(a, b) | ||
70 | return f(b, a) | ||
71 | end | ||
72 | end | ||
73 | |||
74 | function fun.find(xs, f) | ||
75 | if type(xs) == "function" then | ||
76 | for v in xs do | ||
77 | local x = f(v) | ||
78 | if x then | ||
79 | return x | ||
80 | end | ||
81 | end | ||
82 | elseif type(xs) == "table" then | ||
83 | for _, v in ipairs(xs) do | ||
84 | local x = f(v) | ||
85 | if x then | ||
86 | return x | ||
87 | end | ||
88 | end | ||
89 | end | ||
90 | end | ||
91 | |||
92 | function fun.partial(f, ...) | ||
93 | local n = select("#", ...) | ||
94 | if n == 1 then | ||
95 | local a = ... | ||
96 | return function(...) | ||
97 | return f(a, ...) | ||
98 | end | ||
99 | elseif n == 2 then | ||
100 | local a, b = ... | ||
101 | return function(...) | ||
102 | return f(a, b, ...) | ||
103 | end | ||
104 | else | ||
105 | local pargs = { n = n, ... } | ||
106 | return function(...) | ||
107 | local m = select("#", ...) | ||
108 | local fargs = { ... } | ||
109 | local args = {} | ||
110 | for i = 1, n do | ||
111 | args[i] = pargs[i] | ||
112 | end | ||
113 | for i = 1, m do | ||
114 | args[i+n] = fargs[i] | ||
115 | end | ||
116 | return f(unpack(args, 1, n+m)) | ||
117 | end | ||
118 | end | ||
119 | end | ||
120 | |||
121 | function fun.memoize(fn) | ||
122 | local memory = setmetatable({}, { __mode = "k" }) | ||
123 | local errors = setmetatable({}, { __mode = "k" }) | ||
124 | local NIL = {} | ||
125 | return function(arg) | ||
126 | if memory[arg] then | ||
127 | if memory[arg] == NIL then | ||
128 | return nil, errors[arg] | ||
129 | end | ||
130 | return memory[arg] | ||
131 | end | ||
132 | local ret1, ret2 = fn(arg) | ||
133 | if ret1 ~= nil then | ||
134 | memory[arg] = ret1 | ||
135 | else | ||
136 | memory[arg] = NIL | ||
137 | errors[arg] = ret2 | ||
138 | end | ||
139 | return ret1, ret2 | ||
140 | end | ||
141 | end | ||
142 | |||
143 | return fun | ||
diff --git a/src/luarocks/fun.lua b/src/luarocks/fun.lua index 80bf7c20..b315711d 100644 --- a/src/luarocks/fun.lua +++ b/src/luarocks/fun.lua | |||
@@ -1,8 +1,7 @@ | |||
1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local math = _tl_compat and _tl_compat.math or math; local table = _tl_compat and _tl_compat.table or table; local _tl_table_unpack = unpack or table.unpack | ||
1 | 2 | ||
2 | --- A set of basic functional utilities | ||
3 | local fun = {} | 3 | local fun = {} |
4 | 4 | ||
5 | local unpack = table.unpack or unpack | ||
6 | 5 | ||
7 | function fun.concat(xs, ys) | 6 | function fun.concat(xs, ys) |
8 | local rs = {} | 7 | local rs = {} |
@@ -13,6 +12,7 @@ function fun.concat(xs, ys) | |||
13 | for i = 1, #ys do | 12 | for i = 1, #ys do |
14 | rs[i + n] = ys[i] | 13 | rs[i + n] = ys[i] |
15 | end | 14 | end |
15 | |||
16 | return rs | 16 | return rs |
17 | end | 17 | end |
18 | 18 | ||
@@ -38,7 +38,7 @@ function fun.filter(xs, f) | |||
38 | for i = 1, #xs do | 38 | for i = 1, #xs do |
39 | local v = xs[i] | 39 | local v = xs[i] |
40 | if f(v) then | 40 | if f(v) then |
41 | rs[#rs+1] = v | 41 | rs[#rs + 1] = v |
42 | end | 42 | end |
43 | end | 43 | end |
44 | return rs | 44 | return rs |
@@ -46,12 +46,17 @@ end | |||
46 | 46 | ||
47 | function fun.traverse(t, f) | 47 | function fun.traverse(t, f) |
48 | return fun.map(t, function(x) | 48 | return fun.map(t, function(x) |
49 | return type(x) == "table" and fun.traverse(x, f) or f(x) | 49 | |
50 | if type(x) == "table" then | ||
51 | fun.traverse(x, f) | ||
52 | else | ||
53 | f(x) | ||
54 | end | ||
50 | end) | 55 | end) |
51 | end | 56 | end |
52 | 57 | ||
53 | function fun.reverse_in(t) | 58 | function fun.reverse_in(t) |
54 | for i = 1, math.floor(#t/2) do | 59 | for i = 1, math.floor(#t / 2) do |
55 | local m, n = i, #t - i + 1 | 60 | local m, n = i, #t - i + 1 |
56 | local a, b = t[m], t[n] | 61 | local a, b = t[m], t[n] |
57 | t[m] = b | 62 | t[m] = b |
@@ -111,9 +116,9 @@ function fun.partial(f, ...) | |||
111 | args[i] = pargs[i] | 116 | args[i] = pargs[i] |
112 | end | 117 | end |
113 | for i = 1, m do | 118 | for i = 1, m do |
114 | args[i+n] = fargs[i] | 119 | args[i + n] = fargs[i] |
115 | end | 120 | end |
116 | return f(unpack(args, 1, n+m)) | 121 | return f(_tl_table_unpack(args, 1, n + m)) |
117 | end | 122 | end |
118 | end | 123 | end |
119 | end | 124 | end |
@@ -122,19 +127,19 @@ function fun.memoize(fn) | |||
122 | local memory = setmetatable({}, { __mode = "k" }) | 127 | local memory = setmetatable({}, { __mode = "k" }) |
123 | local errors = setmetatable({}, { __mode = "k" }) | 128 | local errors = setmetatable({}, { __mode = "k" }) |
124 | local NIL = {} | 129 | local NIL = {} |
125 | return function(arg) | 130 | return function(a) |
126 | if memory[arg] then | 131 | if memory[a] then |
127 | if memory[arg] == NIL then | 132 | if memory[a] == NIL then |
128 | return nil, errors[arg] | 133 | return nil, errors[a] |
129 | end | 134 | end |
130 | return memory[arg] | 135 | return memory[a] |
131 | end | 136 | end |
132 | local ret1, ret2 = fn(arg) | 137 | local ret1, ret2 = fn(a) |
133 | if ret1 ~= nil then | 138 | if ret1 ~= nil then |
134 | memory[arg] = ret1 | 139 | memory[a] = ret1 |
135 | else | 140 | else |
136 | memory[arg] = NIL | 141 | memory[a] = NIL |
137 | errors[arg] = ret2 | 142 | errors[a] = ret2 |
138 | end | 143 | end |
139 | return ret1, ret2 | 144 | return ret1, ret2 |
140 | end | 145 | end |
diff --git a/src/luarocks/fun.tl b/src/luarocks/fun.tl index b9960e3b..a63f0404 100644 --- a/src/luarocks/fun.tl +++ b/src/luarocks/fun.tl | |||
@@ -123,23 +123,23 @@ function fun.partial<K>(f: (function(...: any): K), ...: any): (function(...: an | |||
123 | end | 123 | end |
124 | end | 124 | end |
125 | 125 | ||
126 | function fun.memoize(fn) | 126 | function fun.memoize<A, B, C>(fn: (function(A):B, C)): (function(A):B, C) |
127 | local memory = setmetatable({}, { __mode = "k" }) | 127 | local memory: {A: B} = setmetatable({}, { __mode = "k" }) |
128 | local errors = setmetatable({}, { __mode = "k" }) | 128 | local errors: {A: C} = setmetatable({}, { __mode = "k" }) |
129 | local NIL = {} | 129 | local NIL: B = {} as B |
130 | return function(arg) | 130 | return function(a: A): B, C |
131 | if memory[arg] then | 131 | if memory[a] then |
132 | if memory[arg] == NIL then | 132 | if memory[a] == NIL then |
133 | return nil, errors[arg] | 133 | return nil, errors[a] |
134 | end | 134 | end |
135 | return memory[arg] | 135 | return memory[a] |
136 | end | 136 | end |
137 | local ret1, ret2 = fn(arg) | 137 | local ret1, ret2 = fn(a) |
138 | if ret1 ~= nil then | 138 | if ret1 ~= nil then |
139 | memory[arg] = ret1 | 139 | memory[a] = ret1 |
140 | else | 140 | else |
141 | memory[arg] = NIL | 141 | memory[a] = NIL |
142 | errors[arg] = ret2 | 142 | errors[a] = ret2 |
143 | end | 143 | end |
144 | return ret1, ret2 | 144 | return ret1, ret2 |
145 | end | 145 | end |
diff --git a/src/luarocks/type_check.tl b/src/luarocks/type_check.tl index e546492c..09dfa96d 100644 --- a/src/luarocks/type_check.tl +++ b/src/luarocks/type_check.tl | |||
@@ -43,7 +43,7 @@ do | |||
43 | -- and the value is a schema specification. Schema versions are considered | 43 | -- and the value is a schema specification. Schema versions are considered |
44 | -- incremental: version "2.0" only needs to specify what's new/changed from | 44 | -- incremental: version "2.0" only needs to specify what's new/changed from |
45 | -- version "1.0". | 45 | -- version "1.0". |
46 | function type_check.declare_schemas(inputs: {string: any}): {any: any} {any} --? | 46 | function type_check.declare_schemas(inputs: {string: any}): {any: any}, {any} --? |
47 | local schemas = {} | 47 | local schemas = {} |
48 | local parent_version | 48 | local parent_version |
49 | 49 | ||