[Dev-luatex] tex.currentgrouplevel

Jonathan Sauer Jonathan.Sauer at silverstroke.com
Tue Aug 19 11:30:48 CEST 2008


Hello,

> > -- Assume there are TeX two count registers allocated, `stackIndex'
> > -- and `groupIndex'
> > tex.count.stackIndex = 0
> > tex.count.groupLevel = -1
> >
> > -- The `grouped variable' stack
> > local stack = { }
> >
> >
> > -- Sets a `grouped variable'
> > function set(name, value)
> > 	if tex.currentgrouplevel > tex.count.grouplevel then
> > 		-- New group opened since the last time. Create a new
stack
> > 		-- element
> > 		tex.count.stackIndex = tex.count.stackIndex + 1
> > 		stack[tex.count.stackIndex] = { }
> > 		tex.count.groupLevel = tex.currentgrouplevel
> > 		
> > 		-- TODO: Optional: Clear the stack above the new element
to
> > 		-- release old values
> > 	end
> > 	
> > 	-- Add the value
> > 	stack[tex.count.stackIndex][name] = value end
> >
> >
> > -- Gets a `grouped variable'
> > function get(name)
> > 	-- Look through the stack, top to bottom
> > 	for i = tex.count.stackIndex, 1, -1 do
> > 		if stack[i][name] then
> > 			return stack[i][name]
> > 		end
> > 	end
> > 	
> > 	-- Value not found
> > 	return nil
> > end
> 
> Would not work anyway.  Local values would survive across
> \endgroup\begingroup

Why? At \endgroup, tex.count.stackIndex would be reset to the value it
had at the beginning of the group (since it is a tex \count register,
not a Lua variable). Then, after \begingroup, setting a variable would
notice that tex.count.groupLevel (which would also have been reset to
its previous value at \endgroup) is lower than tex.currentgrouplevel,
and a new stack element would be created, replacing the previous
element for this grouping level.


> David Kastrup

Jonathan



More information about the dev-luatex mailing list