diff options
author | Matthew Wild <mwild1@gmail.com> | 2015-05-13 17:00:27 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2015-05-13 17:00:27 +0100 |
commit | a885794fccabfc6dc8cc8e52f83c8ac865ddd8c8 (patch) | |
tree | 65bc2e4d57655c0f62aec527649de4e5f46296d4 /util | |
parent | daec51c435ca77914271200607841d55ff7408d7 (diff) | |
parent | 2f7ac943416fa13023e9d061ffc8020811a4ebf0 (diff) | |
download | prosody-a885794fccabfc6dc8cc8e52f83c8ac865ddd8c8.tar.gz prosody-a885794fccabfc6dc8cc8e52f83c8ac865ddd8c8.zip |
Merge 0.10->trunk
Diffstat (limited to 'util')
-rw-r--r-- | util/dataforms.lua | 4 | ||||
-rw-r--r-- | util/queue.lua | 54 | ||||
-rw-r--r-- | util/serialization.lua | 2 | ||||
-rw-r--r-- | util/set.lua | 11 | ||||
-rw-r--r-- | util/sslconfig.lua | 8 | ||||
-rw-r--r-- | util/xml.lua | 2 |
6 files changed, 68 insertions, 13 deletions
diff --git a/util/dataforms.lua b/util/dataforms.lua index b2988ae7..9f2693b1 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -7,7 +7,7 @@ -- local setmetatable = setmetatable; -local pairs, ipairs = pairs, ipairs; +local ipairs = ipairs; local tostring, type, next = tostring, type, next; local t_concat = table.concat; local st = require "util.stanza"; @@ -32,7 +32,7 @@ function form_t.form(layout, data, formtype) if layout.instructions then form:tag("instructions"):text(layout.instructions):up(); end - for n, field in ipairs(layout) do + for _, field in ipairs(layout) do local field_type = field.type or "text-single"; -- Add field tag form:tag("field", { type = field_type, var = field.name, label = field.label }); diff --git a/util/queue.lua b/util/queue.lua new file mode 100644 index 00000000..afdcaf45 --- /dev/null +++ b/util/queue.lua @@ -0,0 +1,54 @@ +-- Prosody IM +-- Copyright (C) 2008-2015 Matthew Wild +-- Copyright (C) 2008-2015 Waqas Hussain +-- +-- This project is MIT/X11 licensed. Please see the +-- COPYING file in the source package for more information. +-- + +-- Small ringbuffer library (i.e. an efficient FIFO queue with a size limit) +-- (because unbounded dynamically-growing queues are a bad thing...) + +local have_utable, utable = pcall(require, "util.table"); -- For pre-allocation of table + +local function new(size) + -- Head is next insert, tail is next read + local head, tail = 1, 1; + local items = 0; -- Number of stored items + local t = have_utable and utable.create(size, 0) or {}; -- Table to hold items + + return { + size = size; + count = function (self) return items; end; + push = function (self, item) + if items >= size then + return nil, "queue full"; + end + t[head] = item; + items = items + 1; + head = (head%size)+1; + return true; + end; + pop = function (self) + if items == 0 then + return nil; + end + local item; + item, t[tail] = t[tail], 0; + tail = (tail%size)+1; + items = items - 1; + return item; + end; + peek = function (self) + if items == 0 then + return nil; + end + return t[tail]; + end; + }; +end + +return { + new = new; +}; + diff --git a/util/serialization.lua b/util/serialization.lua index 06e45054..04901135 100644 --- a/util/serialization.lua +++ b/util/serialization.lua @@ -11,11 +11,9 @@ local type = type; local tostring = tostring; local t_insert = table.insert; local t_concat = table.concat; -local error = error; local pairs = pairs; local next = next; -local loadstring = loadstring; local pcall = pcall; local debug_traceback = debug.traceback; diff --git a/util/set.lua b/util/set.lua index 04f5f0f4..4be39c17 100644 --- a/util/set.lua +++ b/util/set.lua @@ -34,7 +34,7 @@ function set_mt.__div(set, func) return new_set; end function set_mt.__eq(set1, set2) - local set1, set2 = set1._items, set2._items; + set1, set2 = set1._items, set2._items; for item in pairs(set1) do if not set2[item] then return false; @@ -66,6 +66,9 @@ function new(list) local items = setmetatable({}, items_mt); local set = { _items = items }; + -- We access the set through an upvalue in these methods, so ignore 'self' being unused + --luacheck: ignore 212/self + function set:add(item) items[item] = true; end @@ -82,9 +85,9 @@ function new(list) items[item] = nil; end - function set:add_list(list) - if list then - for _, item in ipairs(list) do + function set:add_list(item_list) + if item_list then + for _, item in ipairs(item_list) do items[item] = true; end end diff --git a/util/sslconfig.lua b/util/sslconfig.lua index 98e61341..42ce37d7 100644 --- a/util/sslconfig.lua +++ b/util/sslconfig.lua @@ -6,11 +6,11 @@ local id = function (v) return v end function handlers.options(a, k, b) local o = a[k] or { }; if type(b) ~= "table" then b = { b } end - for k,v in pairs(b) do - if v == true or v == false then - o[k] = v; + for key, value in pairs(b) do + if value == true or value == false then + o[key] = value; else - o[v] = true; + o[value] = true; end end a[k] = o; diff --git a/util/xml.lua b/util/xml.lua index 3c1d3e51..88ccedde 100644 --- a/util/xml.lua +++ b/util/xml.lua @@ -39,7 +39,7 @@ local parse_xml = (function() function handler:CharacterData(data) stanza:text(data); end - function handler:EndElement(tagname) + function handler:EndElement() stanza:up(); end local parser = lxp.new(handler, "\1"); |