[Dev-luatex] Assignments in TeX's mouth, or: "Dr. Zaius, it can talk!"

Jonathan Sauer Jonathan.Sauer at silverstroke.com
Tue Aug 14 12:29:25 CEST 2007


> > I do not think that assignments to TeX's registers done in Lua code 
> > should be automatically \global, as it makes writing macros without
> > (intentioned) side-effects much harder. And those macros 
> > are the best, since they can be used anywhere without having to
> > remember that they clobber register \foo, redefine macro \bar et
> > cetera.
> since we have now a nearly unlimited amount of registers one 
> can define dedicated counters for tasks and treat them global 
> also withing the tex code

Well, this is not particularly elegant (admittedly a subjective
opinion). Also, depending on the macro, it will not be reentrant.

BTW: Why is it possible to have 268435456 (2^28) catcode tables?
That strikes me, more than 65536 registers, as nearly unlimited.
Why not "only" 65536, especially since one would likely run out
of memory long before exhausting this amount?

> > So, returning to this mail's subject, I can only say: "Take 
> > your hands off my grouping, you damn dirty Lua code!" ;-)
> well, don't use tex.count then -)  often the same can be 
> accomplished by:
>     tex.sprint("\\count123=",value)

But this is not expandable. Also, the assignment will be executed
after the LuaTeX code, so other Lua code cannot use the register
(it will use the old value). This creates a new kind of
asynchronous execution, similar to TeX's mouth and stomach, only
this time between Lua and TeX.

> which will honor grouping, or a variant of this
>     \count123=\directlua0{... tex.sprint(value) }
> introducing a grouping model in lua itself is messy; one has 
> to live with the fact that both languages hav edifferent 
> models; actually, once there is mplib, there is yet another 
> grouping model -)

Why exactly is it messy? I would assume -- without having looked
into the source -- that to set a register, a procedure is called
with the register type (count, skip ...), the register number, the
new value and a flag if the assignment should be global. This
procedure then takes care of handling the grouping. Why cannot
this procedure be called from Lua code (or the tex library, to be
precise) as well?

To leave the technical standpoint: When writing Lua code, the
programmer uses Lua's scoping model. When accessing TeX's
registers from Lua code, he/she/it uses TeX's grouping model,
since they are part of TeX, not part of the Lua language. I do
not think this is particularly messy.

Still, if assignments using tex.count et.al. stay global, this
should, IMO, be stated in the manual.


More information about the dev-luatex mailing list