1
2
3
4
5
6
7
8
9
10
11
12
13
14\startmodule [json]
15
16\registerctxluafile{utiljsn}{autosuffix}
17\registerctxluafile{utiltbs}{}
18
19
20
21\startluacode
22
23 local tablestore = utilities.tablestore
24 local field = tablestore.field
25
26 interfaces.implement {
27 name = "loadtable",
28 actions = tablestore.load,
29 arguments = { "optional", "optional" },
30 public = true,
31 protected = true,
32 }
33
34 interfaces.implement {
35 name = "tablefield",
36 actions = function(namespace,name)
37 local data = field(namespace,name)
38 if data then
39 context(data)
40 end
41 end,
42 arguments = "2 arguments",
43 public = true,
44 protected = true,
45 }
46
47 interfaces.implement {
48 name = "tablefielddefault",
49 actions = function(namespace,name,default)
50 local data = field(namespace,name,default)
51 if data then
52 context(data)
53 end
54 end,
55 arguments = "3 arguments",
56 public = true,
57 }
58
59 local replace = lpeg.replacer("@","%%")
60 local lpegmatch = lpeg.match
61
62 interfaces.implement {
63 name = "tableformatted",
64 actions = function(namespace,name,fmt)
65 local data = field(namespace,name)
66 if data then
67 context(lpegmatch(replace,fmt),data)
68 end
69 end,
70 arguments = "3 arguments",
71 public = true,
72 }
73
74 interfaces.implement {
75 name = "tablelength",
76 actions = { tablestore.length, context },
77 arguments = "2 arguments",
78 public = true,
79 }
80
81 utilities.json.field = tablestore.field
82 utilities.json.loaded = tablestore.loaded
83 utilities.json.length = tablestore.length
84
85\stopluacode
86
87\let\loadjsonfile \loadtable
88\let\jsonfield \tablefield
89\let\jsonfielddefault \tablefielddefault
90\let\jsonlength \tablelength
91
92\stopmodule
93 |