Changeset

3:372ddb5900d3

verse: Support for loading plugins
author Matthew Wild <mwild1@gmail.com>
date Sat, 28 Nov 2009 22:22:31 +0000
parents 2:9e9f3be09131
children 4:0ef21511c7ff
files init.lua
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/init.lua	Tue Aug 04 18:32:25 2009 +0100
+++ b/init.lua	Sat Nov 28 22:22:31 2009 +0000
@@ -10,6 +10,8 @@
 stream.__index = stream;
 stream_mt = stream;
 
+verse.plugins = {};
+
 function verse.new()
 	local t = {};
 	t.id = tostring(t):match("%x*$");
@@ -69,6 +71,18 @@
 	return self.events.add_handler(name, callback);
 end
 
+function stream:add_plugin(name)
+	if require("verse.plugins."..name) then
+		local ok, err = verse.plugins[name](self);
+		if ok then
+			self:debug("Loaded %s plugin", name);
+		else
+			self:warn("Failed to load %s plugin: %s", name, err);
+		end
+	end
+	return self;
+end
+
 -- Listener factory
 function new_listener(stream)
 	local conn_listener = {};