Software /
code /
verse
Comparison
init.lua @ 173:3112a9e450ac
verse: Make add_plugin only load a plugin once per stream
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 30 Dec 2010 22:59:23 +0000 |
parent | 163:48a47bca9a63 |
child | 205:cbcd45be11a8 |
comparison
equal
deleted
inserted
replaced
172:1a32e9ae79d0 | 173:3112a9e450ac |
---|---|
20 function verse.new(logger, base) | 20 function verse.new(logger, base) |
21 local t = setmetatable(base or {}, stream); | 21 local t = setmetatable(base or {}, stream); |
22 t.id = tostring(t):match("%x*$"); | 22 t.id = tostring(t):match("%x*$"); |
23 t:set_logger(logger, true); | 23 t:set_logger(logger, true); |
24 t.events = events.new(); | 24 t.events = events.new(); |
25 t.plugins = {}; | |
25 return t; | 26 return t; |
26 end | 27 end |
27 | 28 |
28 verse.add_task = require "util.timer".add_task; | 29 verse.add_task = require "util.timer".add_task; |
29 | 30 |
171 end | 172 end |
172 return object; | 173 return object; |
173 end | 174 end |
174 | 175 |
175 function stream:add_plugin(name) | 176 function stream:add_plugin(name) |
177 if self.plugins[name] then return true; end | |
176 if require("verse.plugins."..name) then | 178 if require("verse.plugins."..name) then |
177 local ok, err = verse.plugins[name](self); | 179 local ok, err = verse.plugins[name](self); |
178 if ok ~= false then | 180 if ok ~= false then |
179 self:debug("Loaded %s plugin", name); | 181 self:debug("Loaded %s plugin", name); |
182 self.plugins[name] = true; | |
180 else | 183 else |
181 self:warn("Failed to load %s plugin: %s", name, err); | 184 self:warn("Failed to load %s plugin: %s", name, err); |
182 end | 185 end |
183 end | 186 end |
184 return self; | 187 return self; |