# HG changeset patch # User Matthew Wild # Date 1289689813 0 # Node ID f8d61da5bcc155083866f9a6dee51c8c06449dd4 # Parent e2cfc6b8fe5d7229ecfda468cb48a064c9da2a25 util.filters: Support for 'filter hooks' that get called when a session is initialized for filters diff -r e2cfc6b8fe5d -r f8d61da5bcc1 util/filters.lua --- a/util/filters.lua Sat Nov 13 04:12:49 2010 +0000 +++ b/util/filters.lua Sat Nov 13 23:10:13 2010 +0000 @@ -10,6 +10,8 @@ module "filters" +local new_filter_hooks = {}; + function initialize(session) if not session.filters then local filters = {}; @@ -19,13 +21,18 @@ local filter_list = filters[type]; if filter_list then for i = 1, #filter_list do - data = filter_list[i](data); + data = filter_list[i](data, session); if data == nil then break; end end end return data; end end + + for i=1,#new_filter_hooks do + new_filter_hooks[i](session); + end + return session.filter; end @@ -65,4 +72,8 @@ end end +function add_filter_hook(callback) + t_insert(new_filter_hooks, callback); +end + return _M;