summaryrefslogtreecommitdiff
path: root/tex/context/base/pack-obj.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2010-07-04 15:32:09 +0300
committerMarius <mariausol@gmail.com>2010-07-04 15:32:09 +0300
commit85b7bc695629926641c7cb752fd478adfdf374f3 (patch)
tree80293f5aaa7b95a500a78392c39688d8ee7a32fc /tex/context/base/pack-obj.lua
downloadcontext-85b7bc695629926641c7cb752fd478adfdf374f3.tar.gz
stable 2010-05-24 13:10
Diffstat (limited to 'tex/context/base/pack-obj.lua')
-rw-r--r--tex/context/base/pack-obj.lua54
1 files changed, 54 insertions, 0 deletions
diff --git a/tex/context/base/pack-obj.lua b/tex/context/base/pack-obj.lua
new file mode 100644
index 000000000..0ee46fc99
--- /dev/null
+++ b/tex/context/base/pack-obj.lua
@@ -0,0 +1,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
+