core-two.lua /size: 4734 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
core-two
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to core-two.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
local
next
=
next
10
local
remove
,
concat
=
table
.
remove
,
table
.
concat
11
local
allocate
=
utilities
.
storage
.
allocate
12 13
--[[ldx-- 14<p>We save multi-pass information in the main utility table. This is a 15bit of a mess because we support old and new methods.</p> 16--ldx]]
--
17 18
local
collected
=
allocate
(
)
19
local
tobesaved
=
allocate
(
)
20 21
local
jobpasses
=
{
22
collected
=
collected
,
23
tobesaved
=
tobesaved
,
24
}
25 26
job
.
passes
=
jobpasses
27 28
local
function
initializer
(
)
29
collected
=
jobpasses
.
collected
30
tobesaved
=
jobpasses
.
tobesaved
31
end
32 33
job
.
register
(
'
job.passes.collected
'
,
tobesaved
,
initializer
,
nil
)
34 35
local
function
define
(
id
)
36
local
p
=
tobesaved
[
id
]
37
if
not
p
then
38
p
=
{
}
39
tobesaved
[
id
]
=
p
40
end
41
return
p
42
end
43 44
local
function
save
(
id
,
str
,
index
)
45
local
jti
=
define
(
id
)
46
if
index
then
47
jti
[
index
]
=
str
48
else
49
jti
[
#
jti
+
1
]
=
str
50
end
51
end
52 53
local
function
savetagged
(
id
,
tag
,
str
)
54
local
jti
=
define
(
id
)
55
jti
[
tag
]
=
str
56
end
57 58
local
function
getdata
(
id
,
index
,
default
)
59
local
jti
=
collected
[
id
]
60
local
value
=
jti
and
jti
[
index
]
61
return
value
~
=
"
"
and
value
or
default
or
"
"
62
end
63 64
local
function
getfield
(
id
,
index
,
tag
,
default
)
65
local
jti
=
collected
[
id
]
66
jti
=
jti
and
jti
[
index
]
67
local
value
=
jti
and
jti
[
tag
]
68
return
value
~
=
"
"
and
value
or
default
or
"
"
69
end
70 71
local
function
getcollected
(
id
)
72
return
collected
[
id
]
or
{
}
73
end
74 75
local
function
gettobesaved
(
id
)
76
return
define
(
id
)
77
end
78 79
local
function
get
(
id
)
80
local
jti
=
collected
[
id
]
81
if
jti
and
#
jti
>
0
then
82
return
remove
(
jti
,
1
)
83
end
84
end
85 86
local
function
first
(
id
)
87
local
jti
=
collected
[
id
]
88
return
jti
and
jti
[
1
]
89
end
90 91
local
function
last
(
id
)
92
local
jti
=
collected
[
id
]
93
return
jti
and
jti
[
#
jti
]
94
end
95 96
local
function
find
(
id
,
n
)
97
local
jti
=
collected
[
id
]
98
return
jti
and
jti
[
n
]
or
nil
99
end
100 101
local
function
count
(
id
)
102
local
jti
=
collected
[
id
]
103
return
jti
and
#
jti
or
0
104
end
105 106
local
function
list
(
id
)
107
local
jti
=
collected
[
id
]
108
if
jti
then
109
return
concat
(
jti
,
'
,
'
)
110
end
111
end
112 113
local
function
inlist
(
id
,
str
)
114
local
jti
=
collected
[
id
]
115
if
jti
then
116
for
_
,
v
in
next
,
jti
do
117
if
v
=
=
str
then
118
return
true
119
end
120
end
121
end
122
return
false
123
end
124 125
local
check
=
first
126 127
jobpasses
.
define
=
define
128
jobpasses
.
save
=
save
129
jobpasses
.
savetagged
=
savetagged
130
jobpasses
.
getdata
=
getdata
131
jobpasses
.
getfield
=
getfield
132
jobpasses
.
getcollected
=
getcollected
133
jobpasses
.
gettobesaved
=
gettobesaved
134
jobpasses
.
get
=
get
135
jobpasses
.
first
=
first
136
jobpasses
.
last
=
last
137
jobpasses
.
find
=
find
138
jobpasses
.
list
=
list
139
jobpasses
.
count
=
count
140
jobpasses
.
check
=
check
141
jobpasses
.
inlist
=
inlist
142 143
-- interface
144 145
local
implement
=
interfaces
.
implement
146 147
implement
{
name
=
"
gettwopassdata
"
,
actions
=
{
get
,
context
}
,
arguments
=
"
string
"
}
148
implement
{
name
=
"
getfirsttwopassdata
"
,
actions
=
{
first
,
context
}
,
arguments
=
"
string
"
}
149
implement
{
name
=
"
getlasttwopassdata
"
,
actions
=
{
last
,
context
}
,
arguments
=
"
string
"
}
150
implement
{
name
=
"
findtwopassdata
"
,
actions
=
{
find
,
context
}
,
arguments
=
"
2 strings
"
}
151
implement
{
name
=
"
gettwopassdatalist
"
,
actions
=
{
list
,
context
}
,
arguments
=
"
string
"
}
152
implement
{
name
=
"
counttwopassdata
"
,
actions
=
{
count
,
context
}
,
arguments
=
"
string
"
}
153
implement
{
name
=
"
checktwopassdata
"
,
actions
=
{
check
,
context
}
,
arguments
=
"
string
"
}
154 155
implement
{
156
name
=
"
definetwopasslist
"
,
157
actions
=
define
,
158
arguments
=
"
string
"
159
}
160 161
implement
{
162
name
=
"
savetwopassdata
"
,
163
actions
=
save
,
164
arguments
=
"
2 strings
"
,
165
}
166 167
implement
{
168
name
=
"
savetaggedtwopassdata
"
,
169
actions
=
savetagged
,
170
arguments
=
"
3 strings
"
,
171
}
172 173
implement
{
174
name
=
"
doifelseintwopassdata
"
,
175
actions
=
{
inlist
,
commands
.
doifelse
}
,
176
arguments
=
"
2 strings
"
,
177
}
178 179
-- local ctx_latelua = context.latelua
180 181
-- implement {
182
-- name = "lazysavetwopassdata",
183
-- arguments = "3 strings",
184
-- public = true,
185
-- actions = function(a,b,c)
186
-- ctx_latelua(function() save(a,c) end)
187
-- end,
188
-- }
189 190
-- implement {
191
-- name = "lazysavetaggedtwopassdata",
192
-- arguments = "3 strings",
193
-- public = true,
194
-- actions = function(a,b,c)
195
-- ctx_latelua(function() savetagged(a,b,c) end)
196
-- end,
197
-- }
198