1if not modules then modules = { } end modules ['cldf-ver'] = {
2 version = 1.001,
3 comment = "companion to cldf-ver.mkiv",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7}
8
9
10
11
12
13local concat, tohandle = table.concat, table.tohandle
14local splitlines, strip = string.splitlines, string.strip
15local tostring, type = tostring, type
16local assignbuffer = buffers.assign
17
18local context = context
19
20context.tobuffer = assignbuffer
21
22function context.tolines(str,strip)
23 local lines = type(str) == "string" and splitlines(str) or str
24 for i=1,#lines do
25 if strip then
26 context(strip(lines[i]) .. " ")
27 else
28 context(lines[i] .. " ")
29 end
30 end
31end
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
61local t_buffer = { "t_o_c_o_n_t_e_x_t" }
62local t_typing = { "typing" }
63local t_type = { "type" }
64
65local function flush(s,inline)
66 assignbuffer("t_o_c_o_n_t_e_x_t",s)
67 context[inline and "typeinlinebuffer" or "typebuffer"](t_buffer)
68 context.resetbuffer(t_buffer)
69end
70
71local function t_tocontext(t,s)
72 local s = table.serialize(t,s)
73 context(function() flush(s,false) end)
74end
75
76local function s_tocontext(first,second,...)
77 local s = second and concat({ first, second, ... }, " ") or first
78 context(function() flush(s,true) end)
79end
80
81local function b_tocontext(b)
82 s_tocontext(tostring(b))
83end
84
85table .tocontext = t_tocontext
86string .tocontext = s_tocontext
87boolean.tocontext = b_tocontext
88number .tocontext = s_tocontext
89
90local tocontext = {
91 ["string"] = s_tocontext,
92 ["table"] = t_tocontext,
93 ["boolean"] = b_tocontext,
94 ["number"] = s_tocontext,
95 ["function"] = function() s_tocontext("<function>") end,
96 ["nil"] = function() s_tocontext("<nil>") end,
97
98}
99
100table.setmetatableindex(tocontext,function(t,k)
101 local v = function(s)
102 s_tocontext("<"..tostring(s)..">")
103 end
104 t[k] = v
105 return v
106end)
107
108table.setmetatablecall(tocontext,function(t,k,...)
109 tocontext[type(k)](k)
110end)
111
112context.tocontext = tocontext
113
114 |