Changeset

889:bb959588bbc4

Added core.objectmanager
author Waqas Hussain <waqas20@gmail.com>
date Sun, 08 Mar 2009 01:07:29 +0500
parents 888:1059230969c3
children 890:5b8da51b0843
files core/objectmanager.lua plugins/mod_xmlrpc.lua
diffstat 2 files changed, 63 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/objectmanager.lua	Sun Mar 08 01:07:29 2009 +0500
@@ -0,0 +1,60 @@
+
+local new_multitable = require "util.multitable".new;
+local t_insert = table.insert;
+local t_concat = table.concat;
+local tostring = tostring;
+local unpack = unpack;
+local pairs = pairs;
+local error = error;
+local type = type;
+local _G = _G;
+
+local data = new_multitable();
+
+module "objectmanager"
+
+function set(...)
+	return data:set(...);
+end
+function remove(...)
+	return data:remove(...);
+end
+function get(...)
+	return data:get(...);
+end
+
+local function get_path(path)
+	if type(path) == "table" then return path; end
+	local s = {};
+	for part in tostring(path):gmatch("[%w_]+") do
+		t_insert(s, part);
+	end
+	return s;
+end
+
+function get_object(path)
+	path = get_path(path)
+	return data:get(unpack(path)), path;
+end
+function set_object(path, object)
+	path = get_path(path);
+	data:set(unpack(path), object);
+end
+
+data:set("ls", function(_dir)
+	local obj, dir = get_object(_dir);
+	if not obj then error("object not found: " .. t_concat(dir, '/')); end
+	local r = {};
+	if type(obj) == "table" then
+		for key, val in pairs(obj) do
+			r[key] = type(val);
+		end
+	end
+	return r;
+end);
+data:set("get", get_object);
+data:set("set", set_object);
+data:set("echo", function(...) return {...}; end);
+data:set("_G", _G);
+
+return _M;
--- a/plugins/mod_xmlrpc.lua	Sun Mar 08 01:06:37 2009 +0500
+++ b/plugins/mod_xmlrpc.lua	Sun Mar 08 01:07:29 2009 +0500
@@ -60,11 +60,12 @@
 	return stanza.tags[1];
 end
 
-local function get_method(method)
+--[[local function get_method(method)
 	return function(...)
 		return {method = method; args = {...}};
 	end
-end
+end]]
+local get_method = require "core.objectmanager".get_object;
 
 local function handle_xmlrpc_request(method, args)
 	method = get_method(method);