From afc79ce5bdec2e242ab2d19cdfe236958c7e2275 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Thu, 1 Aug 2024 22:04:19 +0300 Subject: more changes --- src/luarocks/core/vers.tl | 7 ++++--- src/luarocks/queries.tl | 1 - src/luarocks/upload/multipart.tl | 38 ++++++++++++++++++++------------------ src/mimetypes.d.tl | 2 +- 4 files changed, 25 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/luarocks/core/vers.tl b/src/luarocks/core/vers.tl index 554296af..eae6d3d5 100644 --- a/src/luarocks/core/vers.tl +++ b/src/luarocks/core/vers.tl @@ -8,9 +8,10 @@ local record vers metamethod __le: function(Version, Version): boolean end - record Constraints + record Constraint op: string version: Version | string + no_upgrade: boolean end end @@ -28,7 +29,7 @@ local deltas: {string: integer} = { } local type Version = vers.Version -local type Constraints = vers.Constraints +local type Constraint = vers.Constraint local version_mt: metatable = { --- Equality comparison for versions. @@ -196,7 +197,7 @@ end -- @param constraints table: An array of constraints in table format. -- @return boolean: True if version satisfies all constraints, -- false otherwise. -function vers.match_constraints(version: Version, constraints: {Constraints}): boolean +function vers.match_constraints(version: Version, constraints: {Constraint}): boolean local ok = true setmetatable(version, version_mt) for _, constr in ipairs(constraints) do diff --git a/src/luarocks/queries.tl b/src/luarocks/queries.tl index 15394c4d..3848bd2e 100644 --- a/src/luarocks/queries.tl +++ b/src/luarocks/queries.tl @@ -200,7 +200,6 @@ end -- @param query table: a query table -- @return string: a result such as `my_user/my_rock 1.0` or `my_rock`. function query_mt.__tostring(self: Query): string - -- function query_mt:__tostring(): string local out = {} if self.namespace then table.insert(out, self.namespace) diff --git a/src/luarocks/upload/multipart.tl b/src/luarocks/upload/multipart.tl index d6a5c012..2be9c45f 100644 --- a/src/luarocks/upload/multipart.tl +++ b/src/luarocks/upload/multipart.tl @@ -1,17 +1,17 @@ local record multipart - record TableMap - map: {K: V} - array: {V} + record Parameters + {{string, string | File}} + map: {string: string | File} end end -local type TableMap = multipart.TableMap +local type Parameters = multipart.Parameters local record File - mimetype: string --! TEMP + mimetype: string fname: string - mime: function(File): string --! TEMP + mime: function(File): string end -- socket.url.escape(s) from LuaSocket 3.0rc1 --? @@ -21,13 +21,13 @@ function multipart.url_escape(s: string): string end)) end -function File.mime(self: File): string --! TEMP +function File.mime(self: File): string if not self.mimetype then - local mimetypes_ok, mimetypes = pcall(require, "luarocks.upload.mimetypes") --! TEMP + local mimetypes_ok, mimetypes = pcall(require, "mimetypes") if mimetypes_ok then - self.mimetype = mimetypes.guess(self.fname) --! TEMP + self.mimetype = mimetypes.guess(self.fname) end - self.mimetype = self.mimetype or "application/octet-stream" --! TEMP + self.mimetype = self.mimetype or "application/octet-stream" end return self.mimetype end @@ -62,10 +62,10 @@ end -- {key2, value2}, -- key3: value3 -- } -function multipart.encode(params: TableMap): string, string --! Table map type - local tuples = {} --! type - for i = 1, #params.array do - tuples[i] = params.array[i] +function multipart.encode(params: Parameters): string, string --! Table map type + local tuples: {{string, string | File}} = {} --! type + for i = 1, #params do + tuples[i] = params[i] end for k,v in pairs(params.map) do if k is string then @@ -78,7 +78,7 @@ function multipart.encode(params: TableMap): string, string --! k = multipart.url_escape(k) local buffer: {string} = { 'Content-Disposition: form-data; name="' .. k .. '"' } local content: string - if type(v) == "table" and v.__class == File then + if v is File then buffer[1] = buffer[1] .. ('; filename="' .. v.fname:gsub(".*[/\\]", "") .. '"') table.insert(buffer, "Content-type: " .. v:mime()) content = v:content() @@ -105,12 +105,14 @@ function multipart.encode(params: TableMap): string, string --! "\r\n", "--", boundary, "--", "\r\n" }), boundary end -function multipart.new_file(fname: string, mime: string): File --! TEMP +function multipart.new_file(fname: string, mime: string): File local self: File = {} + setmetatable(self, { __index = File }) - self.__class = File --! + self.__class = File --! no such field in teal + self.fname = fname - self.mimetype = mime --TEMP + self.mimetype = mime return self end diff --git a/src/mimetypes.d.tl b/src/mimetypes.d.tl index 3b6ad692..a735225d 100644 --- a/src/mimetypes.d.tl +++ b/src/mimetypes.d.tl @@ -1,5 +1,5 @@ local record mimetypes - guess: function(string): string --! TEMP + guess: function(string): string end return mimetypes \ No newline at end of file -- cgit v1.2.3-55-g6feb