-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmnode.lua
64 lines (54 loc) · 1.19 KB
/
mnode.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module('mnode', package.seeall)
local nodes = {}
local blocks = setmetatable({},{__mode="v"})
function get(key)
return nodes[key]
end
function set(key, v)
nodes[key] = v
end
function get_block(key)
return blocks[key]
end
function flush_node(node, path, final)
return true
end
function flush_data(block, node, path, final)
return true
end
local block_mt = {
__index = function(o,k)
return rawget(o,'_data')[k]
end,
__newindex = function(o, k, v)
local x = rawget(o,'_data')
x[k] = v
end,
__call = function(o,t,i)
return next(rawget(o, '_data'), i)
end
}
local node_mt = {
__index = function(o,k)
return rawget(o,'_data')[k]
end,
__newindex = function(o, k, v)
local x = rawget(o,'_data')
x[k] = v
end,
__call = function(o,t,i)
return next(rawget(o, '_data'), i)
end
}
function block(t)
local key = function() end
local n = setmetatable({_key= key, _data=t or {}}, block_mt)
blocks[key] = n
return n
end
function node(t)
local key = function() end
local n = setmetatable({_key= key, _data=t or {}}, node_mt)
nodes[key] = n
return n
end