prosody-modules/mod_mix/helpers.lib.lua

24 lines
641 B
Lua
Raw Normal View History

-- Helper functions for mod_mix
function find(array, f)
-- Searches for an element for which f returns true. The first element
-- and its index are returned. If none are found, then -1, nil is returned.
--
-- f is a function that takes the value and returns either true or false.
for i, v in pairs(array) do
if f(v) then return i, v; end
end
return -1, nil;
end
function find_str(array, str)
-- Returns the index of str in array. -1 if array does not contain str
local i, v = find(array, function(v) return v == str end);
return i;
end
return {
find_str = find_str,
find = find,
};