On Wed, Feb 15, 2012 at 9:02 AM, Paul Isambert <[email protected]> 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 head = tex.box[0].head > local t = { [head] = true } > for n in node.traverse(head) do > texio.write_nl(tostring(t[n])) > texio.write_nl(tostring(n == head)) > 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.
n==head is managed by __eq(n,head) handler so can happen that __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 local head_copy = head rawequal(head_copy,head) gives true , i.e head_copy and head have the same identity. (and of course head_copy == head is true ) As far I know, keys are based on identities, so t[n] and t[head] differs. -- luigi
