summaryrefslogtreecommitdiff
path: root/otfl-node-res.lua
diff options
context:
space:
mode:
authorElie Roux <elie.roux@telecom-bretagne.eu>2009-04-12 21:17:28 +0200
committerElie Roux <elie.roux@telecom-bretagne.eu>2009-04-12 21:17:28 +0200
commite86146694fb4159c4ae2ad9969c6c992a19e9c09 (patch)
treec85077dc4545f5df461e5e21bcf1c3897c42fbeb /otfl-node-res.lua
parent5a642e00686d0a9354480fea2aced3d1c4fc47a8 (diff)
downloadluaotfload-e86146694fb4159c4ae2ad9969c6c992a19e9c09.tar.gz
syncronizing with the latest ConTeXt beta, fixing bugs
Diffstat (limited to 'otfl-node-res.lua')
-rw-r--r--otfl-node-res.lua110
1 files changed, 110 insertions, 0 deletions
diff --git a/otfl-node-res.lua b/otfl-node-res.lua
new file mode 100644
index 0000000..c8d815b
--- /dev/null
+++ b/otfl-node-res.lua
@@ -0,0 +1,110 @@
+if not modules then modules = { } end modules ['node-res'] = {
+ version = 1.001,
+ comment = "companion to node-ini.tex",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local gmatch, format = string.gmatch, string.format
+local copy_node, free_node, new_node = node.copy, node.free, node.new
+
+--[[ldx--
+<p>The next function is not that much needed but in <l n='context'/> we use
+for debugging <l n='luatex'/> node management.</p>
+--ldx]]--
+
+nodes = nodes or { }
+
+local reserved = { }
+
+function nodes.register(n)
+ reserved[#reserved+1] = n
+ return n
+end
+
+function nodes.cleanup_reserved(nofboxes) -- todo
+ nodes.tracers.steppers.reset() -- todo: make a registration subsystem
+ local nr, nl = #reserved, 0
+ for i=1,nr do
+ free_node(reserved[i])
+ end
+ if nofboxes then
+ local tb = tex.box
+ for i=0,nofboxes do
+ local l = tb[i]
+ if l then
+ free_node(tb[i])
+ nl = nl + 1
+ end
+ end
+ end
+ reserved = { }
+ return nr, nl, nofboxes -- can be nil
+end
+
+function nodes.usage()
+ local t = { }
+ for n, tag in gmatch(status.node_mem_usage,"(%d+) ([a-z_]+)") do
+ t[tag] = n
+ end
+ return t
+end
+
+local pdfliteral = nodes.register(new_node("whatsit",8)) pdfliteral.mode = 1
+local disc = nodes.register(new_node("disc"))
+local kern = nodes.register(new_node("kern",1))
+local penalty = nodes.register(new_node("penalty"))
+local glue = nodes.register(new_node("glue"))
+local glue_spec = nodes.register(new_node("glue_spec"))
+local glyph = nodes.register(new_node("glyph",0))
+local textdir = nodes.register(new_node("whatsit",7))
+
+function nodes.glyph(fnt,chr)
+ local n = copy_node(glyph)
+ if fnt then n.font = fnt end
+ if chr then n.char = chr end
+ return n
+end
+function nodes.penalty(p)
+ local n = copy_node(penalty)
+ n.penalty = p
+ return n
+end
+function nodes.kern(k)
+ local n = copy_node(kern)
+ n.kern = k
+ return n
+end
+function nodes.glue(width,stretch,shrink)
+ local n, s = copy_node(glue), copy_node(glue_spec)
+ s.width, s.stretch, s.shrink = width, stretch, shrink
+ n.spec = s
+ return n
+end
+function nodes.glue_spec(width,stretch,shrink)
+ local s = copy_node(glue_spec)
+ s.width, s.stretch, s.shrink = width, stretch, shrink
+ return s
+end
+function nodes.disc()
+ return copy_node(disc)
+end
+function nodes.pdfliteral(str)
+ local t = copy_node(pdfliteral)
+ t.data = str
+ return t
+end
+function nodes.textdir(dir)
+ local t = copy_node(textdir)
+ t.dir = dir
+ return t
+end
+
+statistics.register("cleaned up reserved nodes", function()
+ return format("%s nodes, %s lists of %s", nodes.cleanup_reserved(tex.count["lastallocatedbox"]))
+end) -- \topofboxstack
+
+statistics.register("node memory usage", function() -- comes after cleanup !
+ return status.node_mem_usage
+end)