page-ins.lua /size: 2790 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
page-ins
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to page-mix.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 11
structures
=
structures
or
{
}
12
structures
.
inserts
=
structures
.
inserts
or
{
}
13
local
inserts
=
structures
.
inserts
14 15
local
allocate
=
utilities
.
storage
.
allocate
16 17
inserts
.
stored
=
inserts
.
stored
or
allocate
{
}
-- combining them in one is inefficient in the
18
inserts
.
data
=
inserts
.
data
or
allocate
{
}
-- bytecode storage pool
19 20
local
variables
=
interfaces
.
variables
21
local
v_page
=
variables
.
page
22 23
local
context
=
context
24
local
implement
=
interfaces
.
implement
25 26
storage
.
register
(
"
structures/inserts/stored
"
,
inserts
.
stored
,
"
structures.inserts.stored
"
)
27 28
local
data
=
inserts
.
data
29
local
stored
=
inserts
.
stored
30 31
for
name
,
specification
in
next
,
stored
do
32
data
[
specification
.
number
]
=
specification
33
data
[
name
]
=
specification
34
end
35 36
function
inserts
.
define
(
name
,
specification
)
37
specification
.
name
=
name
38
local
number
=
specification
.
number
or
0
39
data
[
name
]
=
specification
40
data
[
number
]
=
specification
41
-- only needed at runtime as this get stored in a bytecode register
42
stored
[
name
]
=
specification
43
if
not
specification
.
location
then
44
specification
.
location
=
v_page
45
end
46
return
specification
47
end
48 49
function
inserts
.
setup
(
name
,
settings
)
50
local
specification
=
data
[
name
]
51
for
k
,
v
in
next
,
settings
do
52
-- maybe trace change
53
specification
[
k
]
=
v
54
end
55
return
specification
56
end
57 58
function
inserts
.
setlocation
(
name
,
location
)
-- a practical fast one
59
data
[
name
]
.
location
=
location
60
end
61 62
function
inserts
.
getlocation
(
name
,
location
)
63
return
data
[
name
]
.
location
or
v_page
64
end
65 66
function
inserts
.
getdata
(
name
)
-- or number
67
return
data
[
name
]
68
end
69 70
function
inserts
.
getname
(
number
)
71
return
data
[
name
]
.
name
72
end
73 74
function
inserts
.
getnumber
(
name
)
75
return
data
[
name
]
.
number
76
end
77 78
-- interface
79 80
implement
{
81
name
=
"
defineinsertion
"
,
82
actions
=
inserts
.
define
,
83
arguments
=
{
84
"
string
"
,
85
{
86
{
"
number
"
,
"
integer
"
}
87
}
88
}
89
}
90 91
implement
{
92
name
=
"
setupinsertion
"
,
93
actions
=
inserts
.
setup
,
94
arguments
=
{
95
"
string
"
,
96
{
97
{
"
location
"
}
98
}
99
}
100
}
101 102
implement
{
103
name
=
"
setinsertionlocation
"
,
104
actions
=
inserts
.
setlocation
,
105
arguments
=
"
2 strings
"
,
106
}
107 108
implement
{
109
name
=
"
insertionnumber
"
,
110
actions
=
function
(
name
)
context
(
data
[
name
]
.
number
or
0
)
end
,
111
arguments
=
"
string
"
112
}
113 114