From 7d8161f6699e674c760feca300447fc56fd79c32 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Sun, 28 Jul 2024 13:20:46 +0300 Subject: reference --- src/luarocks/results-original.lua | 62 +++++++++++++++++++++++++++++++++++++ src/luarocks/results.lua | 62 ------------------------------------- src/luarocks/results.tl | 64 +++++++++++++++++++++++++++++++++++++++ src/luarocks/type_check.tl | 14 +++++---- 4 files changed, 134 insertions(+), 68 deletions(-) create mode 100644 src/luarocks/results-original.lua delete mode 100644 src/luarocks/results.lua create mode 100644 src/luarocks/results.tl (limited to 'src') 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 @@ +local results = {} + +local vers = require("luarocks.core.vers") +local util = require("luarocks.util") + +local result_mt = {} + +result_mt.__index = result_mt + +function result_mt.type() + return "result" +end + +function results.new(name, version, repo, arch, namespace) + assert(type(name) == "string" and not name:match("/")) + assert(type(version) == "string") + assert(type(repo) == "string") + assert(type(arch) == "string" or not arch) + assert(type(namespace) == "string" or not namespace) + + if not namespace then + name, namespace = util.split_namespace(name) + end + + local self = { + name = name, + version = version, + namespace = namespace, + arch = arch, + repo = repo, + } + + return setmetatable(self, result_mt) +end + +--- Test the name field of a query. +-- If query has a boolean field substring set to true, +-- then substring match is performed; otherwise, exact string +-- comparison is done. +-- @param query table: A query in dependency table format. +-- @param name string: A package name. +-- @return boolean: True if names match, false otherwise. +local function match_name(query, name) + if query.substring then + return name:find(query.name, 0, true) and true or false + else + return name == query.name + end +end + +--- Returns true if the result satisfies a given query. +-- @param query: a query. +-- @return boolean. +function result_mt:satisfies(query) + assert(query:type() == "query") + return match_name(query, self.name) + and (query.arch[self.arch] or query.arch["any"]) + and ((not query.namespace) or (query.namespace == self.namespace)) + and vers.match_constraints(vers.parse_version(self.version), query.constraints) +end + +return results diff --git a/src/luarocks/results.lua b/src/luarocks/results.lua deleted file mode 100644 index c14862de..00000000 --- a/src/luarocks/results.lua +++ /dev/null @@ -1,62 +0,0 @@ -local results = {} - -local vers = require("luarocks.core.vers") -local util = require("luarocks.util") - -local result_mt = {} - -result_mt.__index = result_mt - -function result_mt.type() - return "result" -end - -function results.new(name, version, repo, arch, namespace) - assert(type(name) == "string" and not name:match("/")) - assert(type(version) == "string") - assert(type(repo) == "string") - assert(type(arch) == "string" or not arch) - assert(type(namespace) == "string" or not namespace) - - if not namespace then - name, namespace = util.split_namespace(name) - end - - local self = { - name = name, - version = version, - namespace = namespace, - arch = arch, - repo = repo, - } - - return setmetatable(self, result_mt) -end - ---- Test the name field of a query. --- If query has a boolean field substring set to true, --- then substring match is performed; otherwise, exact string --- comparison is done. --- @param query table: A query in dependency table format. --- @param name string: A package name. --- @return boolean: True if names match, false otherwise. -local function match_name(query, name) - if query.substring then - return name:find(query.name, 0, true) and true or false - else - return name == query.name - end -end - ---- Returns true if the result satisfies a given query. --- @param query: a query. --- @return boolean. -function result_mt:satisfies(query) - assert(query:type() == "query") - return match_name(query, self.name) - and (query.arch[self.arch] or query.arch["any"]) - and ((not query.namespace) or (query.namespace == self.namespace)) - and vers.match_constraints(vers.parse_version(self.version), query.constraints) -end - -return results 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 @@ +local record results + +end + +local vers = require("luarocks.core.vers") +local util = require("luarocks.util") + +local result_mt: metatable = {} + +result_mt.__index = result_mt + +function result_mt.type() + return "result" +end + +function results.new(name, version, repo, arch, namespace) + assert(type(name) == "string" and not name:match("/")) + assert(type(version) == "string") + assert(type(repo) == "string") + assert(type(arch) == "string" or not arch) + assert(type(namespace) == "string" or not namespace) + + if not namespace then + name, namespace = util.split_namespace(name) + end + + local self = { + name = name, + version = version, + namespace = namespace, + arch = arch, + repo = repo, + } + + return setmetatable(self, result_mt) +end + +--- Test the name field of a query. +-- If query has a boolean field substring set to true, +-- then substring match is performed; otherwise, exact string +-- comparison is done. +-- @param query table: A query in dependency table format. +-- @param name string: A package name. +-- @return boolean: True if names match, false otherwise. +local function match_name(query, name) + if query.substring then + return name:find(query.name, 0, true) and true or false + else + return name == query.name + end +end + +--- Returns true if the result satisfies a given query. +-- @param query: a query. +-- @return boolean. +function result_mt:satisfies(query) + assert(query:type() == "query") + return match_name(query, self.name) + and (query.arch[self.arch] or query.arch["any"]) + and ((not query.namespace) or (query.namespace == self.namespace)) + and vers.match_constraints(vers.parse_version(self.version), query.constraints) +end + +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 @@ -local type_check = {} +local record type_check + MAGIC_PLATFORMS: integer +end local cfg = require("luarocks.core.cfg") local fun = require("luarocks.fun") @@ -12,7 +14,7 @@ local vers = require("luarocks.core.vers") type_check.MAGIC_PLATFORMS = 0xEBABEFAC do - local function fill_in_version(tbl, version) + local function fill_in_version(tbl, version?) for _, v in pairs(tbl) do if v is table then if v._version == nil then @@ -30,7 +32,7 @@ do _any = util.deep_copy(tbl) } tbl[k]._any[k] = nil - elseif type(v) == "table" then + elseif v is table then expand_magic_platforms(v) end end @@ -41,7 +43,7 @@ do -- and the value is a schema specification. Schema versions are considered -- incremental: version "2.0" only needs to specify what's new/changed from -- version "1.0". - function type_check.declare_schemas(inputs) + function type_check.declare_schemas(inputs: {string: any}): {any: any} {any} --? local schemas = {} local parent_version @@ -66,7 +68,7 @@ end -------------------------------------------------------------------------------- -local function check_version(version, typetbl, context) +local function check_version(version: string, typetbl, context: string) local typetbl_version = typetbl._version or "1.0" if vers.compare_versions(typetbl_version, version) then if context == "" then @@ -84,7 +86,7 @@ end -- only their types. Tables are type checked recursively. -- @param version string: The version of the item. -- @param item any: The object being checked. --- @param typetbl any: The type-checking table for the object. +-- @param typetbl any: The type-ch`ecking table for the object. -- @param context string: A string indicating the "context" where the -- error occurred (the full table path), for error messages. -- @return boolean or (nil, string): true if type checking -- cgit v1.2.3-55-g6feb