# HG changeset patch
# User Matthew Wild <mwild1@gmail.com>
# Date 1275495837 -3600
# Node ID 3cf02e5e632b06e61410d99e69b596bfce525ac1
# Parent  50318ac903942a6db0ed93db216dd5b1597e4984
util.filters: Ensure initialize() never initializes an object twice - and return the filter function to the caller

diff -r 50318ac90394 -r 3cf02e5e632b util/filters.lua
--- 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)