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;
11 local t_insert = table.insert;
12 local t_concat = table.concat;
13 local tostring = tostring;
14 local unpack = unpack;
20 local data = new_multitable();
22 module "objectmanager"
28 return data:remove(...);
34 local function get_path(path)
35 if type(path) == "table" then return path; end
37 for part in tostring(path):gmatch("[%w_]+") do
43 function get_object(path)
45 return data:get(unpack(path)), path;
47 function set_object(path, object)
48 path = get_path(path);
49 data:set(unpack(path), object);
52 data:set("ls", function(_dir)
53 local obj, dir = get_object(_dir);
54 if not obj then error("object not found: " .. t_concat(dir, '/')); end
56 if type(obj) == "table" then
57 for key, val in pairs(obj) do
63 data:set("get", get_object);
64 data:set("set", set_object);
65 data:set("echo", function(...) return {...}; end);