[Dev-luatex] Assignments in Lua

Jonathan Sauer Jonathan.Sauer at silverstroke.com
Wed May 21 08:42:51 CEST 2008


Hello,

take the following PlainTeX example (as always ;-):

%&luatex

\catcode`@=11
\def\log#1{\immediate\write\sixt@@n{#1}}
\let~\space

\tracingassigns1
\tracingrestores1
\tracingonline1


\count@=5
\log{Before:~~~~~~~~~~~~~~~~~\the\count@}


\begingroup

\directlua0{tex.count["count@"]=23}
\log{In group:~~~~~~~~~~~~~~~\the\count@}

\endgroup


\log{After \string\endgroup:~~~~~~~~\the\count@}

\bye


This results in:

This is LuaTeX, Version snapshot-0.25.3-2008051713 (Web2C 7.5.6)
(Assignments.tex{into \tracingonline=1}
{changing \count255=92}
{into \count255=5}
Before:                 5
{reassigning [no_local_whatsits]=0}
{reassigning [no_local_dirs]=0}
{changing \count255=5}
{into \count255=23}
In group:               23
{restoring \count255=5}
After \endgroup:        5
 )
(see the transcript file for additional information)
No pages of output.
Transcript written on Assignments.log.


Now, a few months and betas ago, assignments made inside Lua to
tex.count et cetera were always global (see my posting on August 14th
2007 on this mailing list). Now it seems that they respect grouping.

Is this meant to stay or is it an unintended side-effect of some other
change? Looking into the source ('set_tex_count_register' in
luatex.web), it seems that this change is deliberate.

If it is a feature (which I'd be very grateful for, since it would
simplify a lot of things), how do I perform \global assignments in
Lua? As far as I can see from the source, I cannot pass an optional
third parameter to tex.setcount:

	tex.setcount(<string|number> register, <number> value, <boolean>
global)

I would try my hand at a patch to implement this, but unfortunately, I
cannot find the function prototype for set_tex_count_register. A
sketch:

-	Modify <set_tex_count_register> et.al. so that 'a' is no longer 
	a constant local variable, but a parameter.

-	In ltexlib.c, check for an optional boolean using
<lua_toboolean>,
	then pass either zero (local/false) or four (global/true) as the
	third parameter to <set_tex_count_register> et.al.

-	Add a call to @<Adjust \(f)for the setting of \.{\\globaldefs}@>
	in <set_tex_count_register> et.al. so that \globaldefs works
	correctly.

I'm not sure about the last point, though, since it would mean that
TeX would influence Lua's behaviour. OTOH, adding that code would
make Lua and TeX behave consistently.


Another thing: Setting an attribute using tex.attribute does not seem
to add the attribute to nodes, contrary to setting it in TeX. Most
likely this is because in TeX, the attribute list cache is reset
(luatex.web lines 28106f) and the number of the largest used attribute
register is adjusted, which is not done in Lua (luatex.web lines
34646ff).

Adding

	if (j)>max_used_attr then max_used_attr:=(j);
	attr_list_cache:=cache_disabled;

in luatex.web in function 'set_tex_attribute_register' before line
34650 ('word_define(j+attribute_base,v);') fixes this (for both 
'tex.setattribute(...)' and 'tex.attribute = ...').


And while we're at it: In luatex.wb line 27777,

	help1("I'll pretend you didn't say \long or \outer or
\global.");

should be

	help1("I'll pretend you didn't say \long or \outer or \global or
\protected.");


Jonathan



More information about the dev-luatex mailing list