[luatex] First (optional?) arguments of tex.getcount and friends.

Dirk Laurie dpl at sun.ac.za
Tue May 10 16:32:54 CEST 2011


On Tue, May 10, 2011 at 03:44:48PM +0200, Taco Hoekwater wrote:
> On 05/10/2011 03:42 PM, Paul Isambert wrote:
> > Hello all,
> >
> > I have noticed that the function tex.getcount() and similar can take any
> > number of arguments and ignore them all but the last. E.g.:
> >
> > \directlua{
> > texio.write_nl(tex.getcount("a string", nothing, node.new(11), 55, 0))
> > }
> >
> > returns "1", i.e. the value of count 0, ignoring the string, the nil
> > value, the node, and the number.
> >
> > Is that normal? Am I missing something? My LuaTeX is 0.71.
> 
> I am not surprised: lua pushes the arguments on a stack, and then the
> getcount function takes the topmost entry. I could add an explicit
> test for the number of arguments, but that is a bit of wasted effort,
> in Hans' and my opinion.
It is normal in Lua to ignore any extra arguments, but functions written 
in Lua that use only one argument would ignore all except the _first_.  
It is easy to achieve that from C too: the Lua manual says:
    More specifically, if the stack has n elements, then index 1 
    represents the first element (that is, the element that was 
    pushed onto the stack first) and index n represents the last 
    element; index -1 also represents the last element (that is, 
    the element at the top) and index -n represents the first element.
So it's a question of using index 1 instead of index -1.  

But should we be using the function tex.getcount()?  It is not documented 
in luatexref-t.pdf (at least, my PDF viewer's search function does not 
find it).  Since even documented functions “can (and will) be changed 
without prior notice”, aren't undocumented ones not even more dangerous?

Dirk



More information about the luatex mailing list