diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-04-21 03:15:34 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-04-21 03:15:34 +0000 |
| commit | 434e8e014cb21b8d15d512b966ea4f397fd0d369 (patch) | |
| tree | f8384d8064364331bf0549b2f518742d8f65ea9d /samples/tinyirc.lua | |
| parent | 4e3cf63c95fc3c01a1c759e237678e9d3b2b8494 (diff) | |
| download | luasocket-434e8e014cb21b8d15d512b966ea4f397fd0d369.tar.gz luasocket-434e8e014cb21b8d15d512b966ea4f397fd0d369.tar.bz2 luasocket-434e8e014cb21b8d15d512b966ea4f397fd0d369.zip | |
Better connection handling.
Diffstat (limited to 'samples/tinyirc.lua')
| -rw-r--r-- | samples/tinyirc.lua | 25 |
1 files changed, 17 insertions, 8 deletions
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() |
