<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Le 01/11/2011 10:03, Arno Trautmann a écrit :<br>
<span style="white-space: pre;">> Hi Patrick,<br>
><br>
> thanks for your answer!<br>
><br>
> Patrick Gundlach wrote:<br>
>>> this is again a rather simple question and I am sorry
for taking your time for this …<br>
>>> In short, I want to reverse all glyph nodes in a
line, and/or all lines in a paragraph. I tried something like the
following (with the idea to store all lines in a list, then
replace the lines with the list in reversed order):<br>
>>><br>
>>> function reverse(head)<br>
>>><br>
>>> newlines = {}<br>
>>> i = 1<br>
>>> for line in node.traverse_id(node.id"hhead",head) do<br>
>>> newlines[i] = line<br>
>><br>
>> a lua idiom is newlines[#newlines + 1] = ... - easer to
read to the average Lua hackr.<br>
><br>
> Oh, of course … I fear I'll never get used to this Lua style
…</span><br>
<br>
Or table.insert(newlines, line).<br>
<br>
<span style="white-space: pre;">>>> i = i+1<br>
>>> end<br>
>>><br>
>>> j = #newlines<br>
>>><br>
>>> for line in node.traverse_id(node.id"hhead",head) do<br>
>>> node.insert_before(head,line,newlines[j])<br>
>>> j = j-1<br>
>>> end<br>
>>> return head<br>
>>> end<br>
>><br>
>> I have to admit that I don't understand exactly what is
going on here.<br>
><br>
> Me neither ;)<br>
><br>
>> 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.<br>
><br>
> But shouldn't the node.insert_* just do the same?</span><br>
<br>
They do, as far as I can tell.<br>
<br>
Alternate solution which reverse all nodes in a list:<br>
<br>
function invert_list (h)<br>
local l<br>
for n in node.traverse(h) do<br>
if l then<br>
l = node.insert_before(l, l, node.copy(n))<br>
else<br>
l = node.copy(n)<br>
end<br>
end<br>
node.flush_list(h)<br>
return l<br>
end<br>
<br>
Best,<br>
Paul<br>
<br>
</body>
</html>