[Dev-luatex] A mechanism to know which registers are already allocated?

Paul Isambert zappathustra at free.fr
Sun Jun 10 11:17:57 CEST 2012


Hello all,

When you write something that isn't tied to any format, the successful
allocation of registers depends on the same macros being defined in all
formats (e.g. \newcount). (Admittedly, you can do very well without
registers by using Lua variable, but only for counts and dimens.)

Unfortunately, for attributes, you either have \newattribute in ConTeXt
(as far as I can tell from the sources), while in plain and LaTeX you
have \newluatexattribute iff you're willing to load luatexbase-attr
(which I'm not, although I appreciate the effort). In other words, there
is no ``tradition'' here on which one could rely.

Now, could it be possible to implement e.g. a "tex.counts" table, whose
entries would be \countdef'ed names and the values would be the number
of the associated registers? Then one could easily reserve a new register
on the fly without having to rely on the same macros, e.g.:

\def\FindFreeRegister#1{%
  \directlua{%
    local t = {}
    for _, c in pairs(tex["#1"]) do
      t[c] = true
    end
    for i=22, 2^16-1 do
      if not t[i] then
        tex.print(i)
        break
      end
    end}%
  }

\countdef\mycount=\FindFreeRegister{counts}

Actually, any other way to make sure a register isn't associated with a
command would do; the important thing is that it is implemented in the
engine, not in the formats.

Best,
Paul


More information about the dev-luatex mailing list