View Issue Details

IDProjectCategoryView StatusLast Update
0000081luatexluatex limitationpublic2008-09-30 11:49
ReporterJonathan Sauer Assigned ToTaco  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version0.29.0 
Fixed in Version0.30.0 
Summary0000081: No access to \currentgrouplevel from Lua (via tex.currentgrouplevel)
Description(from the LuaTeX mailing list)

Given is the following PlainTeX file:

%&luatex

% \message{\the\currentgrouplevel}
\directlua0{texio.write_nl(tex.currentgrouplevel)}

\bye


This results in:


This is LuaTeX, Version snapshot-0.29.0-2008072919 (Web2C 7.5.7) (currentgrouplevel.tex ! You can't use `\currentgrouplevel' as tex library index.
l.3 ...lua0{texio.write_nl(tex.currentgrouplevel)}

?


Looking into section 4.1.1 of the manual, currentgrouplevel is not in the list of tex's integer parameters -- unfortunately.

I created a small patch to add several internal parameters to the "tex" table, among them \currentgrouplevel. The patch is based on revision 1462:

% diff --normal luatex.web.orig luatex.web
9829a9830,9831
> @!negative:boolean; { always false}
> @!q:halfword; { general purpose index}
9830a9833
> negative:=false;
9844a9848
> last_item: @<Fetch an item in the current node, if appropriate@>;

I adapted this from procedure "scan_something_internal" and added local variables until it compiled (ahem). "q" seems unproblematic, "negative" is a parameter in "scan_something_internal", most likely to handle expressions like "-\currentgrouplevel". As this is not used when accessing the parameters from Lua, I set it to "false".

I only tested it with \currentgrouplevel, \eTeXversion, \pdflastobj, \pdftexversion and \inputlineno; it seems to work.


Test

%&luatex

\begingroup
\begingroup
\directlua0{texio.write_nl(tex.currentgrouplevel)}
\directlua0{texio.write_nl(tex.eTeXversion)}
\directlua0{texio.write_nl(tex.pdflastobj)}
\directlua0{texio.write_nl(tex.pdftexversion)}
\directlua0{texio.write_nl(tex.inputlineno)}
\endgroup
\endgroup

\bye


This is LuaTeX, Version snapshot-0.29.0-2008082107 (Web2C 7.5.7) (currentgrouplevel.tex
2
2
0
200
9 )
No pages of output.
Transcript written on currentgrouplevel.log.
Additional InformationAccess to the current group level would be a quite useful addition in order to create `grouped variables' in Lua (variables whose previous value is restored at the end of a TeX group):


-- 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
TagsNo tags attached.

Activities

Taco

2008-09-24 12:17

administrator   ~0000060

#1496 adds support for:

tex.lastpenalty
tex.lastkern
tex.lastskip
tex.lastnodetype
tex.inputlineno
tex.badness
tex.pdftexversion
tex.pdflastobj
tex.pdflastxform
tex.pdflastximage
tex.pdflastximagepages
tex.pdflastannot
tex.pdflastxpos
tex.pdflastypos
tex.pdfrandomseed
tex.pdflastlink
tex.luatexversion
tex.Alephversion
tex.Omegaversion
tex.Alephminorversion
tex.Omegaminorversion
tex.eTeXminorversion
tex.eTeXversion
tex.currentgrouplevel
tex.currentgrouptype
tex.currentiflevel
tex.currentiftype
tex.currentifbranch
tex.pdflastximagecolordepth

Issue History

Date Modified Username Field Change
2008-08-27 10:30 Jonathan Sauer New Issue
2008-09-24 11:33 Taco Status new => acknowledged
2008-09-24 11:33 Taco Status acknowledged => assigned
2008-09-24 11:33 Taco Assigned To => Taco
2008-09-24 12:17 Taco Status assigned => resolved
2008-09-24 12:17 Taco Fixed in Version => 0.30.0
2008-09-24 12:17 Taco Resolution open => fixed
2008-09-24 12:17 Taco Note Added: 0000060
2008-09-30 11:49 Taco Status resolved => closed