summaryrefslogtreecommitdiff
path: root/tex/context/base/pack-obj.lua
blob: 0ee46fc99d12e0796ca4f0e8c3fd3ede7a8a4c6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
if not modules then modules = { } end modules ['pack-obj'] = {
    version   = 1.001,
    comment   = "companion to pack-obj.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

--[[ldx--
<p>We save object references in the main utility table. jobobjects are
reusable components.</p>
--ldx]]--

local texsprint, texcount = tex.sprint, tex.count

jobobjects           = jobobjects or { }
jobobjects.collected = jobobjects.collected or { }
jobobjects.tobesaved = jobobjects.tobesaved or { }

local collected, tobesaved = jobobjects.collected, jobobjects.tobesaved

local function initializer()
    collected, tobesaved = jobobjects.collected, jobobjects.tobesaved
end

job.register('jobobjects.collected', jobobjects.tobesaved, initializer, nil)

function jobobjects.save(tag,number,page)
    local t = { number, page }
    tobesaved[tag], collected[tag] = t, t
end

function jobobjects.set(tag,number,page)
    collected[tag] = { number, page }
end

function jobobjects.get(tag)
    return collected[tag] or tobesaved[tag]
end

function jobobjects.number(tag,default)
    local o = collected[tag] or tobesaved[tag]
    texsprint((o and o[1]) or default)
end

function jobobjects.page(tag,default)
    local o = collected[tag] or tobesaved[tag]
    texsprint((o and o[2]) or default)
end

function jobobjects.doifelse(tag)
    commands.testcase(collected[tag] or tobesaved[tag])
end