Hello,
I have some trouble to insert something at the start
of a list.
Example (complete example file after PS):
\setbox0=\hbox{XY}
\directlua0{
do
local hlist = tex.box[0]
local pdf_literal = node.new(8,8)% \pdfliteral
pdf_literal.mode = 2 % direct
pdf_literal.data = "1 0 0 rg 1 0 0 RG"
local head = hlist.list
% local current = hlist.list.next % works
local current = hlist.list % fails
hlist.list = node.insert_before(head, current, pdf_literal)
end
}
! LuaTeX error Attempt to node.insert_before() a non-existing node.
Have I misunderstood node.insert_before()?
Yours sincerely
Heiko
Heiko Oberdiek wrote:
Hello,
I have some trouble to insert something at the start of a list.
weird message indeed; this works do local hlist = tex.box[0] local pdf_literal = node.new(8,8)% \pdfliteral pdf_literal.mode = 2 % direct pdf_literal.data = "1 0 0 rg 1 0 0 RG" pdf_literal.next = hlist.list hlist.list = pdf_literal end current assigning to a box (or operating on box related lists are somewhat tricky, internal invisible pointers and such; this interface will probably change a bit; it helps to copy the list, work on the copy and hpack the result
Example (complete example file after PS):
\setbox0=\hbox{XY} \directlua0{ do local hlist = tex.box[0] local pdf_literal = node.new(8,8)% \pdfliteral pdf_literal.mode = 2 % direct pdf_literal.data = "1 0 0 rg 1 0 0 RG" local head = hlist.list % local current = hlist.list.next % works local current = hlist.list % fails hlist.list = node.insert_before(head, current, pdf_literal) end }
! LuaTeX error Attempt to node.insert_before() a non-existing node.
Have I misunderstood node.insert_before()?
Yours sincerely Heiko
PS: Complete example file that can be used with iniTeX, plain-TeX and LaTeX:
\ifnum\catcode`\{=1 \else \catcode`\{=1 \catcode`\}=2 \hsize=6.5in \vsize=8.9in \parfillskip=0pt plus 1fil \fi \font\f=cmr10 \f \pdfoutput=1
\setbox0=\hbox{XY} \directlua0{ do local hlist = tex.box[0] local pdf_literal = node.new(8,8)% \pdfliteral pdf_literal.mode = 2 % direct pdf_literal.data = "1 0 0 rg 1 0 0 RG" local head = hlist.list % local current = hlist.list.next % works local current = hlist.list % fails hlist.list = node.insert_before(head, current, pdf_literal) end } \shipout\hbox{[\box0]}
\csname @@end\endcsname \end _______________________________________________ dev-luatex mailing list dev-luatex@ntg.nl http://www.ntg.nl/mailman/listinfo/dev-luatex
-- ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Sat, Dec 08, 2007 at 12:31:59AM +0100, Hans Hagen wrote:
Heiko Oberdiek wrote:
Hello,
I have some trouble to insert something at the start of a list.
weird message indeed; this works
do local hlist = tex.box[0] local pdf_literal = node.new(8,8)% \pdfliteral pdf_literal.mode = 2 % direct pdf_literal.data = "1 0 0 rg 1 0 0 RG" pdf_literal.next = hlist.list hlist.list = pdf_literal end
Thanks. What about "prev"? * insert_before seems to set this entry, too. * I have seen, the head of the list (variable "hlist/tex.box[0]") has a node "prev" with id "temp" in the example (I have also seen "attribute_list", "if_stack" and the expected "nil"). Is this a bug not being "nil"? Or must the new head node inherit the prev entry from the old head node?
current assigning to a box (or operating on box related lists are somewhat tricky, internal invisible pointers and such; this interface will probably change a bit; it helps to copy the list, work on the copy and hpack the result
The there is the problem with freeing the old node list.
The internal invisible pointers remain invisible, thus it is unknown
whether it is safe to call node.free().
What about global/local box contents?
Or is the copy strategy more safe, if two box registers are used?
\begingroup
\setbox1=\box1
\endgroup
% box 1 is void and takes the result
\setbox0=\hbox{XY}
\directlua0{
do
local hlist = node.copy(tex.box[0])
% manipulating hlist
tex.box[1] = hlist
end
}%
\setbox0=\box1
But insert_before also don't work on the copied list.
And I would want to avoid copying the whole list, because
it would mean copying the whole document:
I am experimenting with color support based on an attribute.
At some time the shipout material needs transforming to add
pdf_literals with color setting. BTW, I haven't found a
direct callback function for this (page shipout/xform generation).
The way via a box register requires catching the shipout box
at TeX level (package atbegshi). But \pdfxform can't catched
in an easy and reliable way.
Yours sincerely
Heiko
Hi Heiko
On Sat, Dec 08, 2007 at 12:31:59AM +0100, Hans Hagen wrote:
Heiko Oberdiek wrote:
Hello,
I have some trouble to insert something at the start of a list.
weird message indeed; this works
do local hlist = tex.box[0] local pdf_literal = node.new(8,8)% \pdfliteral pdf_literal.mode = 2 % direct pdf_literal.data = "1 0 0 rg 1 0 0 RG" pdf_literal.next = hlist.list hlist.list = pdf_literal end
Thanks.
What about "prev"? * insert_before seems to set this entry, too. * I have seen, the head of the list (variable "hlist/tex.box[0]") has a node "prev" with id "temp" in the example (I have also seen "attribute_list", "if_stack" and the expected "nil"). Is this a bug not being "nil"? Or must the new head node inherit the prev entry from the old head node?
at the tex end double linked lists are not needed, but at the lua end it can be handy and the insertion functions assume it; a handy helper is ... tail = node.slide(head) sliding == make a list double linked
What about global/local box contents?
always global, same for registers; lua calls have no grouping so, when using boxes with lua, reserve dedicated ones
Or is the copy strategy more safe, if two box registers are used?
\begingroup \setbox1=\box1 \endgroup % box 1 is void and takes the result \setbox0=\hbox{XY} \directlua0{ do local hlist = node.copy(tex.box[0]) % manipulating hlist tex.box[1] = hlist end }% \setbox0=\box1
copying indeed, or using a dedicated set for lua manipulations
But insert_before also don't work on the copied list.
because of a bug -)
And I would want to avoid copying the whole list, because it would mean copying the whole document:
assigning the page box to a private (for lua) box is fast btw, in practice pages do not have that many nodes and the node.copy and access calls (node.next and such) are quite optimized by now
I am experimenting with color support based on an attribute. At some time the shipout material needs transforming to add pdf_literals with color setting. BTW, I haven't found a direct callback function for this (page shipout/xform generation).
next year callnbacks for shipout and backend related things will be added (after mplib, so after februari) the vpack calbacks, in addition to head, get additional information passed so sometimes that can be used to determine what to do
The way via a box register requires catching the shipout box at TeX level (package atbegshi). But \pdfxform can't catched in an easy and reliable way.
pdf backend functions will be implemented next year hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hans Hagen wrote:
Heiko Oberdiek wrote:
Hello,
I have some trouble to insert something at the start of a list.
weird message indeed; this works
The message (and even the error itself) is accidental, but there is a deeper problem indeed. There are two different possible approaches: 1. make the lua user responsible for nodelist consistency 2. prevent the lua user from doing stupid things, giving as much help as possible (including garbage collection) The current code is almost completely using approach 1, because that is fastest both in development time and runnning time, approach 2 is (in the end) more user-friendly. In this particluar case, the error is simply an oversight: the insert_before should have worked, with all the mentioned caveats. Best wishes, Taco
participants (3)
-
Hans Hagen
-
Heiko Oberdiek
-
Taco Hoekwater