Software / code / verse
Comparison
init.lua @ 3:372ddb5900d3
verse: Support for loading plugins
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 28 Nov 2009 22:22:31 +0000 |
| parent | 2:9e9f3be09131 |
| child | 4:0ef21511c7ff |
comparison
equal
deleted
inserted
replaced
| 2:9e9f3be09131 | 3:372ddb5900d3 |
|---|---|
| 7 local verse = _M; | 7 local verse = _M; |
| 8 | 8 |
| 9 local stream = {}; | 9 local stream = {}; |
| 10 stream.__index = stream; | 10 stream.__index = stream; |
| 11 stream_mt = stream; | 11 stream_mt = stream; |
| 12 | |
| 13 verse.plugins = {}; | |
| 12 | 14 |
| 13 function verse.new() | 15 function verse.new() |
| 14 local t = {}; | 16 local t = {}; |
| 15 t.id = tostring(t):match("%x*$"); | 17 t.id = tostring(t):match("%x*$"); |
| 16 t.logger = logger.init(t.id); | 18 t.logger = logger.init(t.id); |
| 67 | 69 |
| 68 function stream:hook(name, callback) | 70 function stream:hook(name, callback) |
| 69 return self.events.add_handler(name, callback); | 71 return self.events.add_handler(name, callback); |
| 70 end | 72 end |
| 71 | 73 |
| 74 function stream:add_plugin(name) | |
| 75 if require("verse.plugins."..name) then | |
| 76 local ok, err = verse.plugins[name](self); | |
| 77 if ok then | |
| 78 self:debug("Loaded %s plugin", name); | |
| 79 else | |
| 80 self:warn("Failed to load %s plugin: %s", name, err); | |
| 81 end | |
| 82 end | |
| 83 return self; | |
| 84 end | |
| 85 | |
| 72 -- Listener factory | 86 -- Listener factory |
| 73 function new_listener(stream) | 87 function new_listener(stream) |
| 74 local conn_listener = {}; | 88 local conn_listener = {}; |
| 75 | 89 |
| 76 function conn_listener.incoming(conn, data) | 90 function conn_listener.incoming(conn, data) |