2 local new_multitable = require "util.multitable".new;
\r
3 local t_insert = table.insert;
\r
4 local t_concat = table.concat;
\r
5 local tostring = tostring;
\r
6 local unpack = unpack;
\r
12 local data = new_multitable();
\r
14 module "objectmanager"
\r
17 return data:set(...);
\r
19 function remove(...)
\r
20 return data:remove(...);
\r
23 return data:get(...);
\r
26 local function get_path(path)
\r
27 if type(path) == "table" then return path; end
\r
29 for part in tostring(path):gmatch("[%w_]+") do
\r
35 function get_object(path)
\r
36 path = get_path(path)
\r
37 return data:get(unpack(path)), path;
\r
39 function set_object(path, object)
\r
40 path = get_path(path);
\r
41 data:set(unpack(path), object);
\r
44 data:set("ls", function(_dir)
\r
45 local obj, dir = get_object(_dir);
\r
46 if not obj then error("object not found: " .. t_concat(dir, '/')); end
\r
48 if type(obj) == "table" then
\r
49 for key, val in pairs(obj) do
\r
55 data:set("get", get_object);
\r
56 data:set("set", set_object);
\r
57 data:set("echo", function(...) return {...}; end);
\r