diff options
Diffstat (limited to 'samples')
-rw-r--r-- | samples/forward.lua | 12 | ||||
-rw-r--r-- | samples/tinyirc.lua | 25 |
2 files changed, 23 insertions, 14 deletions
diff --git a/samples/forward.lua b/samples/forward.lua index ff65b84..e51c5ce 100644 --- a/samples/forward.lua +++ b/samples/forward.lua | |||
@@ -76,13 +76,13 @@ function connect(who, host, port) | |||
76 | if not ret and err == "timeout" then | 76 | if not ret and err == "timeout" then |
77 | wait(who, "output") | 77 | wait(who, "output") |
78 | ret, err = who:connect(host, port) | 78 | ret, err = who:connect(host, port) |
79 | if not ret and err ~= "already connected" then | ||
80 | kick(who) | ||
81 | kick(context[who].peer) | ||
82 | return | ||
83 | end | ||
79 | end | 84 | end |
80 | if not ret then | 85 | return forward(who) |
81 | kick(who) | ||
82 | kick(context[who].peer) | ||
83 | else | ||
84 | return forward(who) | ||
85 | end | ||
86 | end | 86 | end |
87 | 87 | ||
88 | -- gets rid of a client | 88 | -- gets rid of a client |
diff --git a/samples/tinyirc.lua b/samples/tinyirc.lua index 684e7c0..e3dd517 100644 --- a/samples/tinyirc.lua +++ b/samples/tinyirc.lua | |||
@@ -24,20 +24,29 @@ io.write("Servers bound\n") | |||
24 | -- simple set implementation | 24 | -- simple set implementation |
25 | -- the select function doesn't care about what is passed to it as long as | 25 | -- the select function doesn't care about what is passed to it as long as |
26 | -- it behaves like a table | 26 | -- it behaves like a table |
27 | -- creates a new set data structure | ||
27 | function newset() | 28 | function newset() |
28 | local reverse = {} | 29 | local reverse = {} |
29 | local set = {} | 30 | local set = {} |
30 | setmetatable(set, { __index = { | 31 | return setmetatable(set, {__index = { |
31 | insert = function(set, value) | 32 | insert = function(set, value) |
32 | table.insert(set, value) | 33 | if not reverse[value] then |
33 | reverse[value] = table.getn(set) | 34 | table.insert(set, value) |
35 | reverse[value] = table.getn(set) | ||
36 | end | ||
34 | end, | 37 | end, |
35 | remove = function(set, value) | 38 | remove = function(set, value) |
36 | table.remove(set, reverse[value]) | 39 | local index = reverse[value] |
37 | reverse[value] = nil | 40 | if index then |
38 | end, | 41 | reverse[value] = nil |
42 | local top = table.remove(set) | ||
43 | if top ~= value then | ||
44 | reverse[top] = index | ||
45 | set[index] = top | ||
46 | end | ||
47 | end | ||
48 | end | ||
39 | }}) | 49 | }}) |
40 | return set | ||
41 | end | 50 | end |
42 | 51 | ||
43 | set = newset() | 52 | set = newset() |