Software /
code /
prosody
Changeset
3142:3cf02e5e632b
util.filters: Ensure initialize() never initializes an object twice - and return the filter function to the caller
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 02 Jun 2010 17:23:57 +0100 |
parents | 3141:50318ac90394 |
children | 3143:887a6374f51c |
files | util/filters.lua |
diffstat | 1 files changed, 13 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/util/filters.lua Wed Jun 02 16:53:40 2010 +0100 +++ b/util/filters.lua Wed Jun 02 17:23:57 2010 +0100 @@ -11,19 +11,22 @@ 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)