diff options
author | Matthew Wild <mwild1@gmail.com> | 2010-06-02 17:23:57 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2010-06-02 17:23:57 +0100 |
commit | 881dc8a1052b66d189426b0323005ad8aca2b38c (patch) | |
tree | 0d141dfa473b48bcd9503090cafe67213f069a07 /util | |
parent | 8b5f39bb76df439e8f9042b25c561412fdafebd9 (diff) | |
download | prosody-881dc8a1052b66d189426b0323005ad8aca2b38c.tar.gz prosody-881dc8a1052b66d189426b0323005ad8aca2b38c.zip |
util.filters: Ensure initialize() never initializes an object twice - and return the filter function to the caller
Diffstat (limited to 'util')
-rw-r--r-- | util/filters.lua | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/util/filters.lua b/util/filters.lua index f6a3e77a..0ac4cb56 100644 --- a/util/filters.lua +++ b/util/filters.lua @@ -11,19 +11,22 @@ local t_insert, t_remove = table.insert, table.remove; module "filters" function initialize(session) - local filters = {}; - session.filters = filters; - - function session.filter(type, data) - local filter_list = filters[type]; - if filter_list then - for i = 1, #filter_list do - data = filter_list[i](data); - if data == nil then break; end + if not session.filters then + local filters = {}; + session.filters = filters; + + function session.filter(type, data) + local filter_list = filters[type]; + if filter_list then + for i = 1, #filter_list do + data = filter_list[i](data); + if data == nil then break; end + end end + return data; end - return data; end + return session.filter; end function add_filter(session, type, callback, priority) |