cldf-ver.lua /size: 3198 b    last modification: 2020-07-01 14:35
1
if
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
-- We have better verbatim: context.verbatim so that needs to be looked
10
-- into. We can also directly store in buffers although this variant works
11
-- better when used mixed with other code (synchronization issue).
12 13
local
concat
,
tohandle
=
table
.
concat
,
table
.
tohandle
14
local
splitlines
,
strip
=
string
.
splitlines
,
string
.
strip
15
local
tostring
,
type
=
tostring
,
type
16
local
assignbuffer
=
buffers
.
assign
17 18
local
context
=
context
19 20
context
.
tobuffer
=
assignbuffer
-- (name,str,catcodes)
21 22
function
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
31
end
32 33
-- local function flush(...)
34
-- context(concat { ..., "\r" }) -- was \n
35
-- end
36
--
37
-- somehow this doesn't work any longer .. i need to figure out why
38
--
39
-- local function t_tocontext(t)
40
-- context.starttyping { "typing" } -- else [1] is intercepted
41
-- context.pushcatcodes("verbatim")
42
-- -- tohandle(flush,...)
43
-- context(table.serialize(t))
44
-- context.stoptyping()
45
-- context.popcatcodes()
46
-- end
47
--
48
-- local function s_tocontext(first,second,...) -- we need to catch {\}
49
-- context.type()
50
-- context("{")
51
-- context.pushcatcodes("verbatim")
52
-- if second then
53
-- context(concat({ first, second, ... }, " "))
54
-- else
55
-- context(first) -- no need to waste a { }
56
-- end
57
-- context.popcatcodes()
58
-- context("}")
59
-- end
60 61
local
t_buffer
=
{
"
t_o_c_o_n_t_e_x_t
"
}
62
local
t_typing
=
{
"
typing
"
}
63
local
t_type
=
{
"
type
"
}
64 65
local
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
)
69
end
70 71
local
function
t_tocontext
(
t
)
72
local
s
=
table
.
serialize
(
t
)
73
context
(
function
(
)
flush
(
s
,
false
)
end
)
74
end
75 76
local
function
s_tocontext
(
first
,
second
,
...
)
-- we need to catch {\}
77
local
s
=
second
and
concat
(
{
first
,
second
,
...
}
,
"
"
)
or
first
78
context
(
function
(
)
flush
(
s
,
true
)
end
)
79
end
80 81
local
function
b_tocontext
(
b
)
82
s_tocontext
(
tostring
(
b
)
)
83
end
84 85
table
.
tocontext
=
t_tocontext
86
string
.
tocontext
=
s_tocontext
87
boolean
.
tocontext
=
b_tocontext
88
number
.
tocontext
=
s_tocontext
89 90
local
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
-- ------------ = -------- can be extended elsewhere
98
}
99 100
table
.
setmetatableindex
(
tocontext
,
function
(
t
,
k
)
101
local
v
=
function
(
s
)
102
s_tocontext
(
"
<
"
.
.
tostring
(
s
)
.
.
"
>
"
)
103
end
104
t
[
k
]
=
v
105
return
v
106
end
)
107 108
table
.
setmetatablecall
(
tocontext
,
function
(
t
,
k
,
...
)
109
tocontext
[
type
(
k
)
]
(
k
)
110
end
)
111 112
context
.
tocontext
=
tocontext
113 114