Software /
code /
prosody
Diff
util/filters.lua @ 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 |
parent | 3140:8c6ed6fd2d35 |
child | 3331:57a9cf5f4259 |
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)