Comparison

init.lua @ 98:1dccff7df2d5

verse: Add verse.eventable() to give a passed object :event() and :hook()/:unhook() methods and return it again
author Matthew Wild <mwild1@gmail.com>
date Sat, 21 Aug 2010 14:38:16 +0100
parent 96:f0aec10023aa
child 124:3659ba3b8dfa
comparison
equal deleted inserted replaced
97:ad6006779416 98:1dccff7df2d5
124 124
125 function stream:unhook(name, handler) 125 function stream:unhook(name, handler)
126 return self.events.remove_handler(name, handler); 126 return self.events.remove_handler(name, handler);
127 end 127 end
128 128
129 function verse.eventable(object)
130 object.events = events.new();
131 object.hook, object.unhook = stream.hook, stream.unhook;
132 local fire_event = object.events.fire_event;
133 function object:event(name, ...)
134 return fire_event(name, ...);
135 end
136 return object;
137 end
138
129 function stream:add_plugin(name) 139 function stream:add_plugin(name)
130 if require("verse.plugins."..name) then 140 if require("verse.plugins."..name) then
131 local ok, err = verse.plugins[name](self); 141 local ok, err = verse.plugins[name](self);
132 if ok then 142 if ok then
133 self:debug("Loaded %s plugin", name); 143 self:debug("Loaded %s plugin", name);