Add core.actions for managing server 'actions'; and make modulemanager register actions 'load' and 'unload'

Mon, 12 Jan 2009 04:05:10 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Mon, 12 Jan 2009 04:05:10 +0000
changeset 698
d8a678e40a0a
parent 697
8ddc85fa7602
child 699
30f5dcb654bd

Add core.actions for managing server 'actions'; and make modulemanager register actions 'load' and 'unload'

core/actions.lua file | annotate | diff | comparison | revisions
core/modulemanager.lua file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/actions.lua	Mon Jan 12 04:05:10 2009 +0000
@@ -0,0 +1,19 @@
+
+local actions = {};
+
+function register(path, t)
+	local curr = actions;
+	for comp in path:gmatch("([^/]+)/") do
+		if curr[comp] == nil then
+			curr[comp] = {};
+		end
+		curr = curr[comp];
+		if type(curr) ~= "table" then
+			return nil, "path-taken";
+		end
+	end
+	curr[path:match("/([^/]+)$")] = t;
+	return true;
+end
+
+return { actions = actions, register= register };
\ No newline at end of file
--- a/core/modulemanager.lua	Mon Jan 12 04:02:29 2009 +0000
+++ b/core/modulemanager.lua	Mon Jan 12 04:05:10 2009 +0000
@@ -27,7 +27,7 @@
 local eventmanager = require "core.eventmanager";
 local config = require "core.configmanager";
 local multitable_new = require "util.multitable".new;
-
+local register_actions = require "core.actions".register;
 
 local loadfile, pcall = loadfile, pcall;
 local setmetatable, setfenv, getfenv = setmetatable, setfenv, getfenv;
@@ -254,4 +254,17 @@
 
 --------------------------------------------------------------------
 
+local actions = {};
+
+function actions.load(params)
+	--return true, "Module loaded ("..params.module.." on "..params.host..")";
+	return load(params.host, params.module);
+end
+
+function actions.unload(params)
+	return unload(params.host, params.module);
+end
+
+register_actions("/modules", actions);
+
 return _M;

mercurial