diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-08-22 17:48:56 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
commit | 8d1ef20f81f3014b4dd0dc38e246b91a18b51074 (patch) | |
tree | 26dde9299d5ae788cc9079485b96447e7c721a6e /src | |
parent | a9dfd61a273242b4e8868e8309cd3e1399519082 (diff) | |
download | luarocks-8d1ef20f81f3014b4dd0dc38e246b91a18b51074.tar.gz luarocks-8d1ef20f81f3014b4dd0dc38e246b91a18b51074.tar.bz2 luarocks-8d1ef20f81f3014b4dd0dc38e246b91a18b51074.zip |
Teal: convert luarocks.results
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/results.tl (renamed from src/luarocks/results.lua) | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/luarocks/results.lua b/src/luarocks/results.tl index c14862de..45b3691d 100644 --- a/src/luarocks/results.lua +++ b/src/luarocks/results.tl | |||
@@ -1,28 +1,27 @@ | |||
1 | local results = {} | 1 | local record results |
2 | end | ||
2 | 3 | ||
3 | local vers = require("luarocks.core.vers") | 4 | local vers = require("luarocks.core.vers") |
4 | local util = require("luarocks.util") | 5 | local util = require("luarocks.util") |
6 | local type Query = require("luarocks.core.types.query").Query | ||
5 | 7 | ||
6 | local result_mt = {} | 8 | local type result = require("luarocks.core.types.result") |
9 | local type Result = result.Result | ||
7 | 10 | ||
8 | result_mt.__index = result_mt | 11 | local result_mt: metatable<Result> = {} |
9 | 12 | ||
10 | function result_mt.type() | 13 | result_mt.__index = result.Result |
11 | return "result" | 14 | |
12 | end | 15 | function results.new(name: string, version: string, repo: string, arch?: string, namespace?: string): Result, boolean |
13 | 16 | ||
14 | function results.new(name, version, repo, arch, namespace) | 17 | assert(not name:match("/")) |
15 | assert(type(name) == "string" and not name:match("/")) | 18 | |
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 | 19 | ||
21 | if not namespace then | 20 | if not namespace then |
22 | name, namespace = util.split_namespace(name) | 21 | name, namespace = util.split_namespace(name) |
23 | end | 22 | end |
24 | 23 | ||
25 | local self = { | 24 | local self: Result = { |
26 | name = name, | 25 | name = name, |
27 | version = version, | 26 | version = version, |
28 | namespace = namespace, | 27 | namespace = namespace, |
@@ -40,7 +39,7 @@ end | |||
40 | -- @param query table: A query in dependency table format. | 39 | -- @param query table: A query in dependency table format. |
41 | -- @param name string: A package name. | 40 | -- @param name string: A package name. |
42 | -- @return boolean: True if names match, false otherwise. | 41 | -- @return boolean: True if names match, false otherwise. |
43 | local function match_name(query, name) | 42 | local function match_name(query: Query, name: string): boolean |
44 | if query.substring then | 43 | if query.substring then |
45 | return name:find(query.name, 0, true) and true or false | 44 | return name:find(query.name, 0, true) and true or false |
46 | else | 45 | else |
@@ -51,12 +50,11 @@ end | |||
51 | --- Returns true if the result satisfies a given query. | 50 | --- Returns true if the result satisfies a given query. |
52 | -- @param query: a query. | 51 | -- @param query: a query. |
53 | -- @return boolean. | 52 | -- @return boolean. |
54 | function result_mt:satisfies(query) | 53 | function result.Result:satisfies(query: Query): boolean |
55 | assert(query:type() == "query") | ||
56 | return match_name(query, self.name) | 54 | return match_name(query, self.name) |
57 | and (query.arch[self.arch] or query.arch["any"]) | 55 | and (query.arch[self.arch] or query.arch["any"]) |
58 | and ((not query.namespace) or (query.namespace == self.namespace)) | 56 | and ((not query.namespace) or (query.namespace == self.namespace)) |
59 | and vers.match_constraints(vers.parse_version(self.version), query.constraints) | 57 | and (vers.match_constraints(vers.parse_version(self.version), query.constraints)) |
60 | end | 58 | end |
61 | 59 | ||
62 | return results | 60 | return results |