diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-08-01 21:42:50 +0300 |
---|---|---|
committer | V1K1NGbg <victor@ilchev.com> | 2024-08-05 20:51:31 +0300 |
commit | fcb36443db545fbd5bf7adfde08ce1a800a41c6f (patch) | |
tree | 6281af22e4541a722197ba745fdef7e6144752b2 | |
parent | 969acee77b09fb59420296efcbf25627b1b3b7c4 (diff) | |
download | luarocks-fcb36443db545fbd5bf7adfde08ce1a800a41c6f.tar.gz luarocks-fcb36443db545fbd5bf7adfde08ce1a800a41c6f.tar.bz2 luarocks-fcb36443db545fbd5bf7adfde08ce1a800a41c6f.zip |
results
-rw-r--r-- | src/luarocks/results-original.lua | 62 | ||||
-rw-r--r-- | src/luarocks/results.lua | 59 | ||||
-rw-r--r-- | src/luarocks/results.tl | 12 |
3 files changed, 104 insertions, 29 deletions
diff --git a/src/luarocks/results-original.lua b/src/luarocks/results-original.lua new file mode 100644 index 00000000..c14862de --- /dev/null +++ b/src/luarocks/results-original.lua | |||
@@ -0,0 +1,62 @@ | |||
1 | local results = {} | ||
2 | |||
3 | local vers = require("luarocks.core.vers") | ||
4 | local util = require("luarocks.util") | ||
5 | |||
6 | local result_mt = {} | ||
7 | |||
8 | result_mt.__index = result_mt | ||
9 | |||
10 | function result_mt.type() | ||
11 | return "result" | ||
12 | end | ||
13 | |||
14 | function results.new(name, version, repo, arch, namespace) | ||
15 | assert(type(name) == "string" and not name:match("/")) | ||
16 | assert(type(version) == "string") | ||
17 | assert(type(repo) == "string") | ||
18 | assert(type(arch) == "string" or not arch) | ||
19 | assert(type(namespace) == "string" or not namespace) | ||
20 | |||
21 | if not namespace then | ||
22 | name, namespace = util.split_namespace(name) | ||
23 | end | ||
24 | |||
25 | local self = { | ||
26 | name = name, | ||
27 | version = version, | ||
28 | namespace = namespace, | ||
29 | arch = arch, | ||
30 | repo = repo, | ||
31 | } | ||
32 | |||
33 | return setmetatable(self, result_mt) | ||
34 | end | ||
35 | |||
36 | --- Test the name field of a query. | ||
37 | -- If query has a boolean field substring set to true, | ||
38 | -- then substring match is performed; otherwise, exact string | ||
39 | -- comparison is done. | ||
40 | -- @param query table: A query in dependency table format. | ||
41 | -- @param name string: A package name. | ||
42 | -- @return boolean: True if names match, false otherwise. | ||
43 | local function match_name(query, name) | ||
44 | if query.substring then | ||
45 | return name:find(query.name, 0, true) and true or false | ||
46 | else | ||
47 | return name == query.name | ||
48 | end | ||
49 | end | ||
50 | |||
51 | --- Returns true if the result satisfies a given query. | ||
52 | -- @param query: a query. | ||
53 | -- @return boolean. | ||
54 | function result_mt:satisfies(query) | ||
55 | assert(query:type() == "query") | ||
56 | return match_name(query, self.name) | ||
57 | and (query.arch[self.arch] or query.arch["any"]) | ||
58 | and ((not query.namespace) or (query.namespace == self.namespace)) | ||
59 | and vers.match_constraints(vers.parse_version(self.version), query.constraints) | ||
60 | end | ||
61 | |||
62 | return results | ||
diff --git a/src/luarocks/results.lua b/src/luarocks/results.lua index c14862de..a945c48b 100644 --- a/src/luarocks/results.lua +++ b/src/luarocks/results.lua | |||
@@ -1,22 +1,34 @@ | |||
1 | local results = {} | 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 assert = _tl_compat and _tl_compat.assert or assert; local string = _tl_compat and _tl_compat.string or string; local results = {Results = {}, } |
2 | |||
3 | |||
4 | |||
5 | |||
6 | |||
7 | |||
8 | |||
9 | |||
2 | 10 | ||
3 | local vers = require("luarocks.core.vers") | 11 | local vers = require("luarocks.core.vers") |
4 | local util = require("luarocks.util") | 12 | local util = require("luarocks.util") |
13 | local queries = require("luarocks.queries") | ||
14 | |||
15 | |||
16 | |||
5 | 17 | ||
6 | local result_mt = {} | 18 | local result_mt = {} |
7 | 19 | ||
8 | result_mt.__index = result_mt | 20 | result_mt.__index = results.Results |
9 | 21 | ||
10 | function result_mt.type() | 22 | function results.Results.type() |
11 | return "result" | 23 | return "result" |
12 | end | 24 | end |
13 | 25 | ||
14 | function results.new(name, version, repo, arch, namespace) | 26 | function results.new(name, version, repo, arch, namespace) |
15 | assert(type(name) == "string" and not name:match("/")) | 27 | |
16 | assert(type(version) == "string") | 28 | assert(not name:match("/")) |
17 | assert(type(repo) == "string") | 29 | |
18 | assert(type(arch) == "string" or not arch) | 30 | |
19 | assert(type(namespace) == "string" or not namespace) | 31 | |
20 | 32 | ||
21 | if not namespace then | 33 | if not namespace then |
22 | name, namespace = util.split_namespace(name) | 34 | name, namespace = util.split_namespace(name) |
@@ -33,13 +45,13 @@ function results.new(name, version, repo, arch, namespace) | |||
33 | return setmetatable(self, result_mt) | 45 | return setmetatable(self, result_mt) |
34 | end | 46 | end |
35 | 47 | ||
36 | --- Test the name field of a query. | 48 | |
37 | -- If query has a boolean field substring set to true, | 49 | |
38 | -- then substring match is performed; otherwise, exact string | 50 | |
39 | -- comparison is done. | 51 | |
40 | -- @param query table: A query in dependency table format. | 52 | |
41 | -- @param name string: A package name. | 53 | |
42 | -- @return boolean: True if names match, false otherwise. | 54 | |
43 | local function match_name(query, name) | 55 | local function match_name(query, name) |
44 | if query.substring then | 56 | if query.substring then |
45 | return name:find(query.name, 0, true) and true or false | 57 | return name:find(query.name, 0, true) and true or false |
@@ -48,15 +60,14 @@ local function match_name(query, name) | |||
48 | end | 60 | end |
49 | end | 61 | end |
50 | 62 | ||
51 | --- Returns true if the result satisfies a given query. | 63 | |
52 | -- @param query: a query. | 64 | |
53 | -- @return boolean. | 65 | |
54 | function result_mt:satisfies(query) | 66 | function results.Results:satisfies(query) |
55 | assert(query:type() == "query") | 67 | return match_name(query, self.name) and |
56 | return match_name(query, self.name) | 68 | (query.arch[self.arch] or query.arch["any"]) and |
57 | and (query.arch[self.arch] or query.arch["any"]) | 69 | ((not query.namespace) or (query.namespace == self.namespace)) and |
58 | and ((not query.namespace) or (query.namespace == self.namespace)) | 70 | (vers.match_constraints(vers.parse_version(self.version), query.constraints)) |
59 | and vers.match_constraints(vers.parse_version(self.version), query.constraints) | ||
60 | end | 71 | end |
61 | 72 | ||
62 | return results | 73 | return results |
diff --git a/src/luarocks/results.tl b/src/luarocks/results.tl index 7417db7a..cae6ead9 100644 --- a/src/luarocks/results.tl +++ b/src/luarocks/results.tl | |||
@@ -10,14 +10,16 @@ end | |||
10 | 10 | ||
11 | local vers = require("luarocks.core.vers") | 11 | local vers = require("luarocks.core.vers") |
12 | local util = require("luarocks.util") | 12 | local util = require("luarocks.util") |
13 | local queries = require("luarocks.queries") | ||
13 | 14 | ||
14 | local type Results = results.Results | 15 | local type Results = results.Results |
16 | local type Query = queries.Query | ||
15 | 17 | ||
16 | local result_mt: metatable<Results> = {} | 18 | local result_mt: metatable<Results> = {} |
17 | 19 | ||
18 | result_mt.__index = result_mt | 20 | result_mt.__index = results.Results |
19 | 21 | ||
20 | function result_mt.type() | 22 | function results.Results.type(): string --? remove later |
21 | return "result" | 23 | return "result" |
22 | end | 24 | end |
23 | 25 | ||
@@ -50,7 +52,7 @@ end | |||
50 | -- @param query table: A query in dependency table format. | 52 | -- @param query table: A query in dependency table format. |
51 | -- @param name string: A package name. | 53 | -- @param name string: A package name. |
52 | -- @return boolean: True if names match, false otherwise. | 54 | -- @return boolean: True if names match, false otherwise. |
53 | local function match_name(query: query, name: string): boolean | 55 | local function match_name(query: Query, name: string): boolean |
54 | if query.substring then | 56 | if query.substring then |
55 | return name:find(query.name, 0, true) and true or false | 57 | return name:find(query.name, 0, true) and true or false |
56 | else | 58 | else |
@@ -61,11 +63,11 @@ end | |||
61 | --- Returns true if the result satisfies a given query. | 63 | --- Returns true if the result satisfies a given query. |
62 | -- @param query: a query. | 64 | -- @param query: a query. |
63 | -- @return boolean. | 65 | -- @return boolean. |
64 | function result_mt:satisfies(query: query): Results, boolean | 66 | function results.Results:satisfies(query: Query): boolean |
65 | return match_name(query, self.name) | 67 | return match_name(query, self.name) |
66 | and (query.arch[self.arch] or query.arch["any"]) | 68 | and (query.arch[self.arch] or query.arch["any"]) |
67 | and ((not query.namespace) or (query.namespace == self.namespace)) | 69 | and ((not query.namespace) or (query.namespace == self.namespace)) |
68 | and vers.match_constraints(vers.parse_version(self.version), query.constraints) | 70 | and (vers.match_constraints(vers.parse_version(self.version), query.constraints)) |
69 | end | 71 | end |
70 | 72 | ||
71 | return results | 73 | return results |