Annotate

core/objectmanager.lua @ 2924:8dc4e2e00129

util.windows: Convert from Windows line endings
author Matthew Wild <mwild1@gmail.com>
date Mon, 22 Mar 2010 17:16:28 +0000
parent 2923:b7049746bd29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 889
diff changeset
1 -- Prosody IM
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 889
diff changeset
4 --
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 889
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 889
diff changeset
6 -- COPYING file in the source package for more information.
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 889
diff changeset
7 --
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 889
diff changeset
8
889
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10 local new_multitable = require "util.multitable".new;
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11 local t_insert = table.insert;
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12 local t_concat = table.concat;
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 local tostring = tostring;
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 local unpack = unpack;
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 local pairs = pairs;
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 local error = error;
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 local type = type;
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18 local _G = _G;
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 local data = new_multitable();
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 module "objectmanager"
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 function set(...)
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25 return data:set(...);
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 end
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 function remove(...)
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28 return data:remove(...);
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29 end
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 function get(...)
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 return data:get(...);
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32 end
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 local function get_path(path)
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 if type(path) == "table" then return path; end
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 local s = {};
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 for part in tostring(path):gmatch("[%w_]+") do
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 t_insert(s, part);
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39 end
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 return s;
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41 end
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
43 function get_object(path)
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44 path = get_path(path)
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45 return data:get(unpack(path)), path;
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46 end
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 function set_object(path, object)
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 path = get_path(path);
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49 data:set(unpack(path), object);
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
50 end
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 data:set("ls", function(_dir)
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 local obj, dir = get_object(_dir);
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 if not obj then error("object not found: " .. t_concat(dir, '/')); end
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 local r = {};
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 if type(obj) == "table" then
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
57 for key, val in pairs(obj) do
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
58 r[key] = type(val);
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
59 end
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
60 end
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
61 return r;
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
62 end);
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
63 data:set("get", get_object);
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64 data:set("set", set_object);
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
65 data:set("echo", function(...) return {...}; end);
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66 data:set("_G", _G);
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
67
bb959588bbc4 Added core.objectmanager
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
68 return _M;