author | Matthew Wild <mwild1@gmail.com> |
Wed, 01 May 2013 13:54:31 +0100 | |
branch | sasl |
changeset 5555 | 70a7ef4b6aaa |
parent 1522 | 569d58d21612 |
child 2102 | b5ee3c416609 |
child 2923 | b7049746bd29 |
permissions | -rw-r--r-- |
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
889
diff
changeset
|
1 |
-- Prosody IM |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
889
diff
changeset
|
2 |
-- Copyright (C) 2008-2009 Matthew Wild |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
889
diff
changeset
|
3 |
-- Copyright (C) 2008-2009 Waqas Hussain |
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 | 9 |
|
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; |
|
15 |
local pairs = pairs; |
|
16 |
local error = error; |
|
17 |
local type = type; |
|
18 |
local _G = _G; |
|
19 |
||
20 |
local data = new_multitable(); |
|
21 |
||
22 |
module "objectmanager" |
|
23 |
||
24 |
function set(...) |
|
25 |
return data:set(...); |
|
26 |
end |
|
27 |
function remove(...) |
|
28 |
return data:remove(...); |
|
29 |
end |
|
30 |
function get(...) |
|
31 |
return data:get(...); |
|
32 |
end |
|
33 |
||
34 |
local function get_path(path) |
|
35 |
if type(path) == "table" then return path; end |
|
36 |
local s = {}; |
|
37 |
for part in tostring(path):gmatch("[%w_]+") do |
|
38 |
t_insert(s, part); |
|
39 |
end |
|
40 |
return s; |
|
41 |
end |
|
42 |
||
43 |
function get_object(path) |
|
44 |
path = get_path(path) |
|
45 |
return data:get(unpack(path)), path; |
|
46 |
end |
|
47 |
function set_object(path, object) |
|
48 |
path = get_path(path); |
|
49 |
data:set(unpack(path), object); |
|
50 |
end |
|
51 |
||
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 |
|
55 |
local r = {}; |
|
56 |
if type(obj) == "table" then |
|
57 |
for key, val in pairs(obj) do |
|
58 |
r[key] = type(val); |
|
59 |
end |
|
60 |
end |
|
61 |
return r; |
|
62 |
end); |
|
63 |
data:set("get", get_object); |
|
64 |
data:set("set", set_object); |
|
65 |
data:set("echo", function(...) return {...}; end); |
|
66 |
data:set("_G", _G); |
|
67 |
||
68 |
return _M; |