[luatex] token_filter
Paul Isambert
zappathustra at free.fr
Sat Apr 27 12:40:15 CEST 2013
Arthur Reutenauer <arthur.reutenauer at normalesup.org> a écrit:
> > l.28 of your luaintercharnode.lua, you say:
> >
> > Why the hell can’t I index a table with a table?
> >
> > Well, you can :)
> >
> > local t = { [{1, 1}] = emspace }
> > t[{a = b}] = c
>
> Yes, but observe:
>
> ---- cut before
> \directlua{
> local function log(message)
> texio.write_nl("term and log", message)
> end
>
> local function say_if_node(n, label)
> if node.is_node(n, label) then
> log(label .. " is a node")
> else
> log(label .. " is NOT a node")
> end
> end
>
> local t = { }
> local emspace = node.new(node.id('kern'), 1)
> t[{ 1, 1 }] = emspace
> t[1] = emspace
>
> say_if_node(emspace, "emspace")
> say_if_node(t[{ 1, 1 }], "t[{ 1, 1 }]")
> say_if_node(t[1], "t[1]")
> }
> ---- cut after
>
> prints (amongst others):
>
> ----
> emspace is a node
> t[{ 1, 1 }] is NOT a node
> t[1] is a node
> ----
>
> So something odd is happening when the table index is a table, which
> meant that in practice I couldn't use table as indexes there.
>
> With LuaTeX 0.70.2 from TeX Live 2012, haven't checked with 0.75.
That’s because you’re using two different tables, although they have
the same contents. What should be done is:
local t, tindex = {}, {1, 1}
...
t[tindex] = emspace
...
say_if_node(t[tindex], "t[{ 1, 1 }]")
...
Of course, that solution might not fit your goal.
Otherwise, I’m sure you could hack some metatable magic to the effect
that t[{1, 1}] always works.
Best,
Paul
More information about the luatex
mailing list