Changeset

3625:f8d61da5bcc1

util.filters: Support for 'filter hooks' that get called when a session is initialized for filters
author Matthew Wild <mwild1@gmail.com>
date Sat, 13 Nov 2010 23:10:13 +0000
parents 3624:e2cfc6b8fe5d
children 3626:444f965baed8
files util/filters.lua
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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;