2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
10 local new_multitable = require "util.multitable".new;
\r
11 local t_insert = table.insert;
\r
12 local t_concat = table.concat;
\r
13 local tostring = tostring;
\r
14 local unpack = unpack;
\r
15 local pairs = pairs;
\r
16 local error = error;
\r
20 local data = new_multitable();
\r
22 module "objectmanager"
\r
25 return data:set(...);
\r
27 function remove(...)
\r
28 return data:remove(...);
\r
31 return data:get(...);
\r
34 local function get_path(path)
\r
35 if type(path) == "table" then return path; end
\r
37 for part in tostring(path):gmatch("[%w_]+") do
\r
43 function get_object(path)
\r
44 path = get_path(path)
\r
45 return data:get(unpack(path)), path;
\r
47 function set_object(path, object)
\r
48 path = get_path(path);
\r
49 data:set(unpack(path), object);
\r
52 data:set("ls", function(_dir)
\r
53 local obj, dir = get_object(_dir);
\r
54 if not obj then error("object not found: " .. t_concat(dir, '/')); end
\r
56 if type(obj) == "table" then
\r
57 for key, val in pairs(obj) do
\r
63 data:set("get", get_object);
\r
64 data:set("set", set_object);
\r
65 data:set("echo", function(...) return {...}; end);
\r