On 6/16/2015 10:26 PM, David Carlisle wrote:
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)

then you need access to the underlying register number (301).

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

\attributedef\zeroattribute=0
\attributedef\bar=999

\directlua {
    function attributenumber(name)
local n = newtoken.create(name).mode - newtoken.create("zeroattribute").mode
        if n >= 0 then
            return n
        else
            return false
        end
    end
}

\directlua{print(attributenumber("crap"))}
\directlua{print(attributenumber("bar"))}
\directlua{print(attributenumber("10>color"))}
\directlua{print(attributenumber("10>colormodel"))}

Hans

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
    tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

Reply via email to