-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathtest2.lua
More file actions
62 lines (46 loc) · 987 Bytes
/
test2.lua
File metadata and controls
62 lines (46 loc) · 987 Bytes
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
local tracedoc = require "tracedoc"
local doc = tracedoc.new {}
doc.a = false
doc.b = { x = 1, y = 2 }
doc.c = { a = 3, b = 4 }
tracedoc.opaque(doc.c, true)
local function map(str)
return function (doc, v)
print(str, v)
end
end
local function add_b(doc, x, y)
print("b.x+b.y=", x+y)
end
local function add_c(doc, c)
print("c.a+c.b=", c.a + c.b)
end
local mapping = tracedoc.changeset {
{ "A" , map "A1" , "a" },
{ "A" , map "A2" , "a" },
{ "B" , map "B", "b" },
{ "B" , map "BX" , "b.x" },
{ add_b, "b.x", "b.y" },
{ "C", add_c, "c" },
}
local function map(info)
print("====", info, "====")
tracedoc.mapchange(doc, mapping)
print("------------------")
end
map(1)
doc.a = 0
doc.b.y = 3
doc.c.b = 5
map(2)
doc.a = 1
doc.b.y = 4
map(3)
print("Filter A")
tracedoc.mapupdate(doc, mapping, "A")
print("Filter B")
tracedoc.mapupdate(doc, mapping, "B")
print("Filter null")
tracedoc.mapupdate(doc, mapping, "")
print("Filter All")
tracedoc.mapupdate(doc, mapping)