attr-neg.lua /size: 2768 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
attr-neg
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to attr-neg.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
-- this module is being reconstructed and code will move to other places
10
-- we can also do the nsnone via a metatable and then also se index 0
11 12
local
format
=
string
.
format
13 14
local
attributes
,
nodes
,
utilities
,
logs
,
backends
=
attributes
,
nodes
,
utilities
,
logs
,
backends
15
local
commands
,
context
,
interfaces
=
commands
,
context
,
interfaces
16
local
tex
=
tex
17 18
local
states
=
attributes
.
states
19
local
enableaction
=
nodes
.
tasks
.
enableaction
20
local
nodeinjections
=
backends
.
nodeinjections
21
local
texsetattribute
=
tex
.
setattribute
22
local
variables
=
interfaces
.
variables
23
local
allocate
=
utilities
.
storage
.
allocate
24
local
setmetatableindex
=
table
.
setmetatableindex
25 26
--- negative / positive
27 28
attributes
.
negatives
=
attributes
.
negatives
or
{
}
29
local
negatives
=
attributes
.
negatives
30 31
local
a_negative
=
attributes
.
private
(
"
negative
"
)
32 33
local
v_none
=
interfaces
.
variables
.
none
34 35
negatives
.
data
=
allocate
(
)
36
negatives
.
attribute
=
a_negative
37 38
negatives
.
registered
=
allocate
{
39
[
variables
.
positive
]
=
1
,
40
[
variables
.
negative
]
=
2
,
41
}
42 43
local
data
=
negatives
.
data
44
local
registered
=
negatives
.
registered
45 46
local
function
extender
(
negatives
,
key
)
47
if
key
=
=
"
none
"
then
-- v_none then
48
local
d
=
data
[
1
]
49
negatives
.
none
=
d
50
return
d
51
end
52
end
53 54
local
function
reviver
(
data
,
n
)
55
if
n
=
=
1
then
56
local
d
=
nodeinjections
.
positive
(
)
-- called once
57
data
[
1
]
=
d
58
return
d
59
elseif
n
=
=
2
then
60
local
d
=
nodeinjections
.
negative
(
)
-- called once
61
data
[
2
]
=
d
62
return
d
63
end
64
end
65 66
setmetatableindex
(
negatives
,
extender
)
67
setmetatableindex
(
negatives
.
data
,
reviver
)
68 69
negatives
.
handler
=
nodes
.
installattributehandler
{
70
name
=
"
negative
"
,
71
namespace
=
negatives
,
72
initializer
=
states
.
initialize
,
73
finalizer
=
states
.
finalize
,
74
processor
=
states
.
process
,
75
}
76 77
local
function
register
(
stamp
)
78
return
registered
[
stamp
]
or
registered
.
positive
79
end
80 81
local
function
enable
(
)
82
enableaction
(
"
shipouts
"
,
"
attributes.negatives.handler
"
)
83
end
84 85
negatives
.
register
=
register
86
negatives
.
enable
=
enable
87 88
-- interface
89 90
local
enabled
=
false
91 92
function
negatives
.
set
(
stamp
)
93
if
not
enabled
then
94
enable
(
)
95
enabled
=
true
96
end
97
texsetattribute
(
a_negative
,
register
(
stamp
)
)
98
end
99 100
interfaces
.
implement
{
101
name
=
"
setnegative
"
,
102
actions
=
negatives
.
set
,
103
arguments
=
"
string
"
,
104
}
105