From fcb36443db545fbd5bf7adfde08ce1a800a41c6f Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Thu, 1 Aug 2024 21:42:50 +0300 Subject: results --- src/luarocks/results-original.lua | 62 +++++++++++++++++++++++++++++++++++++++ src/luarocks/results.lua | 59 ++++++++++++++++++++++--------------- src/luarocks/results.tl | 12 ++++---- 3 files changed, 104 insertions(+), 29 deletions(-) create mode 100644 src/luarocks/results-original.lua 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 index c14862de..a945c48b 100644 --- a/src/luarocks/results.lua +++ b/src/luarocks/results.lua @@ -1,22 +1,34 @@ -local results = {} +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 = {}, } + + + + + + + + local vers = require("luarocks.core.vers") local util = require("luarocks.util") +local queries = require("luarocks.queries") + + + local result_mt = {} -result_mt.__index = result_mt +result_mt.__index = results.Results -function result_mt.type() +function results.Results.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) + + assert(not name:match("/")) + + + if not namespace then name, namespace = util.split_namespace(name) @@ -33,13 +45,13 @@ function results.new(name, version, repo, arch, namespace) 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 @@ -48,15 +60,14 @@ local function match_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) + + + +function results.Results:satisfies(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 index 7417db7a..cae6ead9 100644 --- a/src/luarocks/results.tl +++ b/src/luarocks/results.tl @@ -10,14 +10,16 @@ end local vers = require("luarocks.core.vers") local util = require("luarocks.util") +local queries = require("luarocks.queries") local type Results = results.Results +local type Query = queries.Query local result_mt: metatable = {} -result_mt.__index = result_mt +result_mt.__index = results.Results -function result_mt.type() +function results.Results.type(): string --? remove later return "result" end @@ -50,7 +52,7 @@ end -- @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: query, name: string): boolean +local function match_name(query: Query, name: string): boolean if query.substring then return name:find(query.name, 0, true) and true or false else @@ -61,11 +63,11 @@ end --- Returns true if the result satisfies a given query. -- @param query: a query. -- @return boolean. -function result_mt:satisfies(query: query): Results, boolean +function results.Results:satisfies(query: Query): boolean 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) + and (vers.match_constraints(vers.parse_version(self.version), query.constraints)) end return results -- cgit v1.2.3-55-g6feb