diff options
| -rw-r--r-- | src/luarocks/results-original.lua (renamed from src/luarocks/results.lua) | 0 | ||||
| -rw-r--r-- | src/luarocks/results.tl | 64 | ||||
| -rw-r--r-- | src/luarocks/type_check.tl | 14 |
3 files changed, 72 insertions, 6 deletions
diff --git a/src/luarocks/results.lua b/src/luarocks/results-original.lua index c14862de..c14862de 100644 --- a/src/luarocks/results.lua +++ b/src/luarocks/results-original.lua | |||
diff --git a/src/luarocks/results.tl b/src/luarocks/results.tl new file mode 100644 index 00000000..78a46da9 --- /dev/null +++ b/src/luarocks/results.tl | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | local record results | ||
| 2 | |||
| 3 | end | ||
| 4 | |||
| 5 | local vers = require("luarocks.core.vers") | ||
| 6 | local util = require("luarocks.util") | ||
| 7 | |||
| 8 | local result_mt: metatable<any> = {} | ||
| 9 | |||
| 10 | result_mt.__index = result_mt | ||
| 11 | |||
| 12 | function result_mt.type() | ||
| 13 | return "result" | ||
| 14 | end | ||
| 15 | |||
| 16 | function results.new(name, version, repo, arch, namespace) | ||
| 17 | assert(type(name) == "string" and not name:match("/")) | ||
| 18 | assert(type(version) == "string") | ||
| 19 | assert(type(repo) == "string") | ||
| 20 | assert(type(arch) == "string" or not arch) | ||
| 21 | assert(type(namespace) == "string" or not namespace) | ||
| 22 | |||
| 23 | if not namespace then | ||
| 24 | name, namespace = util.split_namespace(name) | ||
| 25 | end | ||
| 26 | |||
| 27 | local self = { | ||
| 28 | name = name, | ||
| 29 | version = version, | ||
| 30 | namespace = namespace, | ||
| 31 | arch = arch, | ||
| 32 | repo = repo, | ||
| 33 | } | ||
| 34 | |||
| 35 | return setmetatable(self, result_mt) | ||
| 36 | end | ||
| 37 | |||
| 38 | --- Test the name field of a query. | ||
| 39 | -- If query has a boolean field substring set to true, | ||
| 40 | -- then substring match is performed; otherwise, exact string | ||
| 41 | -- comparison is done. | ||
| 42 | -- @param query table: A query in dependency table format. | ||
| 43 | -- @param name string: A package name. | ||
| 44 | -- @return boolean: True if names match, false otherwise. | ||
| 45 | local function match_name(query, name) | ||
| 46 | if query.substring then | ||
| 47 | return name:find(query.name, 0, true) and true or false | ||
| 48 | else | ||
| 49 | return name == query.name | ||
| 50 | end | ||
| 51 | end | ||
| 52 | |||
| 53 | --- Returns true if the result satisfies a given query. | ||
| 54 | -- @param query: a query. | ||
| 55 | -- @return boolean. | ||
| 56 | function result_mt:satisfies(query) | ||
| 57 | assert(query:type() == "query") | ||
| 58 | return match_name(query, self.name) | ||
| 59 | and (query.arch[self.arch] or query.arch["any"]) | ||
| 60 | and ((not query.namespace) or (query.namespace == self.namespace)) | ||
| 61 | and vers.match_constraints(vers.parse_version(self.version), query.constraints) | ||
| 62 | end | ||
| 63 | |||
| 64 | return results | ||
diff --git a/src/luarocks/type_check.tl b/src/luarocks/type_check.tl index 0e8ce60f..e546492c 100644 --- a/src/luarocks/type_check.tl +++ b/src/luarocks/type_check.tl | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | 1 | ||
| 2 | local type_check = {} | 2 | local record type_check |
| 3 | MAGIC_PLATFORMS: integer | ||
| 4 | end | ||
| 3 | 5 | ||
| 4 | local cfg = require("luarocks.core.cfg") | 6 | local cfg = require("luarocks.core.cfg") |
| 5 | local fun = require("luarocks.fun") | 7 | local fun = require("luarocks.fun") |
| @@ -12,7 +14,7 @@ local vers = require("luarocks.core.vers") | |||
| 12 | type_check.MAGIC_PLATFORMS = 0xEBABEFAC | 14 | type_check.MAGIC_PLATFORMS = 0xEBABEFAC |
| 13 | 15 | ||
| 14 | do | 16 | do |
| 15 | local function fill_in_version(tbl, version) | 17 | local function fill_in_version(tbl, version?) |
| 16 | for _, v in pairs(tbl) do | 18 | for _, v in pairs(tbl) do |
| 17 | if v is table then | 19 | if v is table then |
| 18 | if v._version == nil then | 20 | if v._version == nil then |
| @@ -30,7 +32,7 @@ do | |||
| 30 | _any = util.deep_copy(tbl) | 32 | _any = util.deep_copy(tbl) |
| 31 | } | 33 | } |
| 32 | tbl[k]._any[k] = nil | 34 | tbl[k]._any[k] = nil |
| 33 | elseif type(v) == "table" then | 35 | elseif v is table then |
| 34 | expand_magic_platforms(v) | 36 | expand_magic_platforms(v) |
| 35 | end | 37 | end |
| 36 | end | 38 | end |
| @@ -41,7 +43,7 @@ do | |||
| 41 | -- and the value is a schema specification. Schema versions are considered | 43 | -- and the value is a schema specification. Schema versions are considered |
| 42 | -- 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 |
| 43 | -- version "1.0". | 45 | -- version "1.0". |
| 44 | function type_check.declare_schemas(inputs) | 46 | function type_check.declare_schemas(inputs: {string: any}): {any: any} {any} --? |
| 45 | local schemas = {} | 47 | local schemas = {} |
| 46 | local parent_version | 48 | local parent_version |
| 47 | 49 | ||
| @@ -66,7 +68,7 @@ end | |||
| 66 | 68 | ||
| 67 | -------------------------------------------------------------------------------- | 69 | -------------------------------------------------------------------------------- |
| 68 | 70 | ||
| 69 | local function check_version(version, typetbl, context) | 71 | local function check_version(version: string, typetbl, context: string) |
| 70 | local typetbl_version = typetbl._version or "1.0" | 72 | local typetbl_version = typetbl._version or "1.0" |
| 71 | if vers.compare_versions(typetbl_version, version) then | 73 | if vers.compare_versions(typetbl_version, version) then |
| 72 | if context == "" then | 74 | if context == "" then |
| @@ -84,7 +86,7 @@ end | |||
| 84 | -- only their types. Tables are type checked recursively. | 86 | -- only their types. Tables are type checked recursively. |
| 85 | -- @param version string: The version of the item. | 87 | -- @param version string: The version of the item. |
| 86 | -- @param item any: The object being checked. | 88 | -- @param item any: The object being checked. |
| 87 | -- @param typetbl any: The type-checking table for the object. | 89 | -- @param typetbl any: The type-ch`ecking table for the object. |
| 88 | -- @param context string: A string indicating the "context" where the | 90 | -- @param context string: A string indicating the "context" where the |
| 89 | -- error occurred (the full table path), for error messages. | 91 | -- error occurred (the full table path), for error messages. |
| 90 | -- @return boolean or (nil, string): true if type checking | 92 | -- @return boolean or (nil, string): true if type checking |
