X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Fset.lua;h=7f45526eb41f97741cfdabd8abc15f114442a0f1;hb=e332947cb586dc7a3bbf9ca1632c07b0ab342f09;hp=84bfe8c42c299e29bcb506ab153198b5677f91b0;hpb=138c5afe227036aa3cfcff2c3e25ff72e6745de4;p=prosody.git diff --git a/util/set.lua b/util/set.lua index 84bfe8c4..7f45526e 100644 --- a/util/set.lua +++ b/util/set.lua @@ -1,4 +1,12 @@ -local ipairs, pairs, setmetatable, next, tostring = +-- Prosody IM +-- Copyright (C) 2008-2010 Matthew Wild +-- Copyright (C) 2008-2010 Waqas Hussain +-- +-- This project is MIT/X11 licensed. Please see the +-- COPYING file in the source package for more information. +-- + +local ipairs, pairs, setmetatable, next, tostring = ipairs, pairs, setmetatable, next, tostring; local t_concat = table.concat; @@ -18,8 +26,9 @@ function set_mt.__div(set, func) local new_set, new_items = _M.new(); local items, new_items = set._items, new_set._items; for item in pairs(items) do - if func(item) then - new_items[item] = true; + local new_item = func(item); + if new_item ~= nil then + new_items[new_item] = true; end end return new_set; @@ -74,8 +83,10 @@ function new(list) end function set:add_list(list) - for _, item in ipairs(list) do - items[item] = true; + if list then + for _, item in ipairs(list) do + items[item] = true; + end end end