1if not modules then modules = { } end modules ['spac-par'] = {
2 version = 1.001,
3 comment = "companion to spac-par.mkxl",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7}
8
9local context = context
10local implement = interfaces.implement
11
12local collected = utilities.storage.allocate()
13local tobesaved = utilities.storage.allocate()
14local wrappers = { }
15
16local jobparwrappers = {
17 collected = collected,
18 tobesaved = tobesaved,
19}
20
21job.parwrappers = jobparwrappers
22
23local function initializer()
24 tobesaved = jobparwrappers.tobesaved
25 collected = jobparwrappers.collected
26end
27
28local function finalizer()
29
30end
31
32job.register('job.parwrappers.collected', tobesaved, initializer, finalizer)
33
34implement {
35 name = "newparwrapper",
36 arguments = "string",
37 actions = function(id)
38 local t = tobesaved[id]
39 local n
40 if t then
41 n = #t + 1
42 t[n] = 0
43 else
44 n = 1
45 tobesaved[id] = { 0 }
46 end
47 wrappers[id] = n
48 end
49}
50
51implement {
52 name = "setparwrapper",
53 arguments = "string",
54 protected = true,
55 actions = function(id)
56 local t = tobesaved[id]
57 local n = #t
58 t[n] = t[n] + 1
59 end
60}
61
62implement {
63 name = "getparwrapper",
64 arguments = "string",
65 public = true,
66 actions = function(id)
67 local t = tobesaved[id]
68 context(t and t[#t] or 0)
69 end
70}
71
72implement {
73 name = "lastparwrapper",
74 arguments = "string",
75 public = true,
76 actions = function(id)
77 local t = collected and collected[id]
78 context(t and t[wrappers[id]] or 0)
79 end
80}
81
82 |