diff options
author | Hans Hagen <pragma@wxs.nl> | 2010-08-19 01:08:00 +0200 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2010-08-19 01:08:00 +0200 |
commit | 174663b0081dd76f91c45fd705262a262a7b1f49 (patch) | |
tree | 554d5d47e81a9263e98fe7091be7e4dbd363482b /tex/context/base/attr-neg.lua | |
parent | e68c228a21a98042c87ef21d9a094b97f941e8de (diff) | |
download | context-174663b0081dd76f91c45fd705262a262a7b1f49.tar.gz |
beta 2010.08.19 01:08
Diffstat (limited to 'tex/context/base/attr-neg.lua')
-rw-r--r-- | tex/context/base/attr-neg.lua | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tex/context/base/attr-neg.lua b/tex/context/base/attr-neg.lua new file mode 100644 index 000000000..ab62fbab5 --- /dev/null +++ b/tex/context/base/attr-neg.lua @@ -0,0 +1,71 @@ +if not modules then modules = { } end modules ['attr-neg'] = { + version = 1.001, + comment = "companion to attr-neg.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +-- this module is being reconstructed and code will move to other places +-- we can also do the nsnone via a metatable and then also se index 0 + +local format = string.format + +local attributes, nodes = attributes, nodes + +local states = attributes.states +local tasks = nodes.tasks +local nodeinjections = backends.nodeinjections + +--- negative / positive + +attributes.negatives = attributes.negatives or { } +local negatives = attributes.negatives +negatives.data = negatives.data or { } +negatives.attribute = attributes.private("negative") + +negatives.registered = { + positive = 1, + negative = 2, +} + +local data, registered = negatives.data, negatives.registered + +local function extender(negatives,key) + if key == "none" then + local d = data[1] + negatives.none = d + return d + end +end + +local function reviver(data,n) + if n == 1 then + local d = nodeinjections.positive() -- called once + data[1] = d + return d + elseif n == 2 then + local d = nodeinjections.negative() -- called once + data[2] = d + return d + end +end + +setmetatable(negatives, { __index = extender }) +setmetatable(negatives.data, { __index = reviver }) + +function negatives.register(stamp) + return registered[stamp] or registered.positive +end + +attributes.negatives.handler = nodes.install_attribute_handler { + name = "negative", + namespace = negatives, + initializer = states.initialize, + finalizer = states.finalize, + processor = states.process, +} + +function negatives.enable() + tasks.enableaction("shipouts","attributes.negatives.handler") +end |