# [luatex] The node returned by node.traverse().

Paul Isambert zappathustra at free.fr
Wed Feb 15 14:44:48 CET 2012

luigi scarso <luigi.scarso at gmail.com> a écrit:
>
> On Wed, Feb 15, 2012 at 9:02 AM, Paul Isambert <zappathustra at free.fr> wrote:
> > Hello there,
> >
> > I have a problem with the identity, so to speak, of nodes returned by
> > node.traverse(); I don't know if I'm missing something (perhaps related
> > to Lua rather than LuaTeX) or what. The following code should illustrate
> > the problem (I do not bother with breaks since there is only one node in
> > the list and one entry in the table):
> >
> > %%%%%%%%%%%
> > \setbox0=\hbox{a}
> >
> > \directlua{
> >  local t = { [head] = true }
> >  for n in node.traverse(head) do
> >    texio.write_nl(tostring(t[n]))
> >    for a in pairs(t) do
> >      if a == n then
> >        texio.write_nl("They match!")
> >      end
> >    end
> >  end
> > }
> The key of t is head,  and head is a userdata.
>
> __eq(n,head) is true based on some considerations of n and head.
>
> On the other side rawequal(n,head) gives false
> so n and head have not the same identity (can be a different address,
> but we don't have a
> way to print addresses in Lua).
> With
> gives true , i.e head_copy and head have the same identity.
>
> As far I know, keys are based on  identities, so t[n] and t[head] differs.

Thank you Luigi; I'd thought about metatable magic but I hadn't considered
rawequal to make sure.

Now I should recast the question: why are "head" an "n" different? I
suppose the answer of course is: because node.traverse() doesn't really
return the node, but then what does it return and why?

Best,
Paul