Software /
code /
prosody
Comparison
util/filters.lua @ 5776:bd0ff8ae98a8
Remove all trailing whitespace
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Fri, 09 Aug 2013 17:48:21 +0200 |
parent | 3943:ad5924c31953 |
child | 5850:e8c743f4213f |
comparison
equal
deleted
inserted
replaced
5775:a6c2b8933507 | 5776:bd0ff8ae98a8 |
---|---|
1 -- Prosody IM | 1 -- Prosody IM |
2 -- Copyright (C) 2008-2010 Matthew Wild | 2 -- Copyright (C) 2008-2010 Matthew Wild |
3 -- Copyright (C) 2008-2010 Waqas Hussain | 3 -- Copyright (C) 2008-2010 Waqas Hussain |
4 -- | 4 -- |
5 -- This project is MIT/X11 licensed. Please see the | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
7 -- | 7 -- |
8 | 8 |
9 local t_insert, t_remove = table.insert, table.remove; | 9 local t_insert, t_remove = table.insert, table.remove; |
14 | 14 |
15 function initialize(session) | 15 function initialize(session) |
16 if not session.filters then | 16 if not session.filters then |
17 local filters = {}; | 17 local filters = {}; |
18 session.filters = filters; | 18 session.filters = filters; |
19 | 19 |
20 function session.filter(type, data) | 20 function session.filter(type, data) |
21 local filter_list = filters[type]; | 21 local filter_list = filters[type]; |
22 if filter_list then | 22 if filter_list then |
23 for i = 1, #filter_list do | 23 for i = 1, #filter_list do |
24 data = filter_list[i](data, session); | 24 data = filter_list[i](data, session); |
26 end | 26 end |
27 end | 27 end |
28 return data; | 28 return data; |
29 end | 29 end |
30 end | 30 end |
31 | 31 |
32 for i=1,#new_filter_hooks do | 32 for i=1,#new_filter_hooks do |
33 new_filter_hooks[i](session); | 33 new_filter_hooks[i](session); |
34 end | 34 end |
35 | 35 |
36 return session.filter; | 36 return session.filter; |
37 end | 37 end |
38 | 38 |
39 function add_filter(session, type, callback, priority) | 39 function add_filter(session, type, callback, priority) |
40 if not session.filters then | 40 if not session.filters then |
41 initialize(session); | 41 initialize(session); |
42 end | 42 end |
43 | 43 |
44 local filter_list = session.filters[type]; | 44 local filter_list = session.filters[type]; |
45 if not filter_list then | 45 if not filter_list then |
46 filter_list = {}; | 46 filter_list = {}; |
47 session.filters[type] = filter_list; | 47 session.filters[type] = filter_list; |
48 end | 48 end |
49 | 49 |
50 priority = priority or 0; | 50 priority = priority or 0; |
51 | 51 |
52 local i = 0; | 52 local i = 0; |
53 repeat | 53 repeat |
54 i = i + 1; | 54 i = i + 1; |
55 until not filter_list[i] or filter_list[filter_list[i]] >= priority; | 55 until not filter_list[i] or filter_list[filter_list[i]] >= priority; |
56 | 56 |
57 t_insert(filter_list, i, callback); | 57 t_insert(filter_list, i, callback); |
58 filter_list[callback] = priority; | 58 filter_list[callback] = priority; |
59 end | 59 end |
60 | 60 |
61 function remove_filter(session, type, callback) | 61 function remove_filter(session, type, callback) |