# [luatex] accessing attribute registers (and other register types)

David Carlisle d.p.carlisle at gmail.com
Tue Jun 16 22:26:52 CEST 2015

If you have an attributedef token defined via

\attributedef\qqq=301
\qqq=53

(or some allocation macro that does that internally)

then you can access the value (53 here) from lua as tex.attribute.qqq

but to use in node callbacks with such as

node.has_attribute(n, attr_number)

Does luatex have a documented way to get from the csname "qqq"
to the register number?

The latex luatexbase package achieves this by wrapping the \attributedef
in a call to \directlua that stores the "qqq"->53 association in its
own lua table.

It seemed to me that luatex must have this information and it ought to be
possible to simplify this just to do a bare \attributedef.

The following code appears to work producing

qqq is attribute: 301 value: 53

hhhz is attribute: 444 value: 99

zzz is count: 200 value: 2

that is the register number and value in each case, but poking into
tex.hashtokens seems like it probably is not the correct thing to do
and I'm not sure I'm supposed to assume that all the countdef tokens
get consecutive identifying integers?

\attributedef\attrzero=0

\countdef\zzz=200
\zzz=2
\def\zz{}
\attributedef\qqq=301
\qqq=53
\def\hmm{lll}

\attributedef\hhhz=444
\hhhz=99

\directlua{
texio.write_nl("")

v=tex.hashtokens()["qqq"][2] - tex.hashtokens()["attrzero"][2]
texio.write_nl("qqq is attribute: "  .. v .. " value: " .. tex.attribute["qqq"])

v=tex.hashtokens()["hhhz"][2] -tex.hashtokens()["attrzero"][2]
texio.write_nl("hhhz is attribute: "  .. v .. " value: " ..
tex.attribute["hhhz"])

v=tex.hashtokens()["zzz"][2] -tex.hashtokens()["pageno"][2]
texio.write_nl("zzz is count: "  .. v.. " value: " .. tex.count["zzz"])

texio.write_nl("")}

\bye