[luatex] reverse node lists

Arno Trautmann Arno.Trautmann at gmx.de
Tue Nov 1 10:34:10 CET 2011


Paul Isambert wrote:
> Le 01/11/2011 10:03, Arno Trautmann a écrit :
>> Oh, of course … I fear I'll never get used to this Lua style …
>
> Or table.insert(newlines, line).

Thousands of ways …

>> >> i = i+1
>> >> end
>> >>
>> >> j = #newlines
>> >>
>> >> for line in node.traverse_id(node.id"hhead",head) do
>> >> node.insert_before(head,line,newlines[j])
>> >> j = j-1
>> >> end
>> >> return head
>> >> end
>> >
>> > I have to admit that I don't understand exactly what is going on here.
>>
>> Me neither ;)
>>
>> > I never use the node.insert_* functions as they are some black magic
> to me, I always change next/prev pointsers manually, so I have the
> feeling of what I have to do.
>>
>> But shouldn't the node.insert_* just do the same?
>
> They do, as far as I can tell.

Well … Taco? What does the master say? Are they equal?

> Alternate solution which reverse all nodes in a list:

Well, I don't want to reverse all nodes. That may be ok for the 
all-glyphs-in-a-line, but not for all-lines-in-a-paragraph, as there may 
be (or, is) other vertical material that should stay where it is.

Still, thanks for your code, it's also a good starting point for me.

cheers
Arno

> function invert_list (h)
> local l
> for n in node.traverse(h) do
> if l then
> l = node.insert_before(l, l, node.copy(n))
> else
> l = node.copy(n)
> end
> end
> node.flush_list(h)
> return l
> end
>
> Best,
> Paul
>
>



More information about the luatex mailing list