Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

TeX (and all newer engines) has the primitive \show which helps me probe macros, and most of the time is enough to understand/remember the implementation (rather than having to go back to the source code).

Is there something similar for Lua commands? For instance, Heiko Oberdiek has written replacements for some pdfTeX primitives in LuaTeX, and I'd like to get more information about them using some hypothetical \showluatexcmd macro.

\input pdftexcmds.sty
\catcode`@=11
\show\pdf@strcmp
%\showluatexcmd{oberdiek.pdftexcmds.strcmp}
\bye
share|improve this question

1 Answer 1

up vote 15 down vote accepted

I seriously doubt that there is something similar for Lua, but you can do the following to find out where the function is defined (to get to the source code).

\directlua{ require("showluatexcmd") }
\def\showluatexcmd#1{\directlua{showluatexcmd.show(#1)}}

\input pdftexcmds.sty
\catcode`@=11
 \show\pdf@strcmp
\showluatexcmd{oberdiek.pdftexcmds.strcmp}
\bye

and the file showluatexcmd.lua:

module(...,package.seeall)

function show( fun )
  local debuginfo = { "source","linedefined","what" }
  for _,v in ipairs(debuginfo) do
    texio.write_nl(string.format("%20s=%q", v, debug.getinfo(fun)[v]))
  end
end

One could extend this probably to directly load the function and display it. But in most cases this won't help as there are a lot of functions that are short and call other functions.

A sample output is

          source="@/opt/texlive2011/texmf-dist/scripts/oberdiek/pdftexcmds.lua"
     linedefined="46"
            what="Lua" )
share|improve this answer
1  
there is also "lastlinedefined", so you could potentially print a portion of the source file .. –  Taco Hoekwater Feb 1 '12 at 8:36
    
I was hoping for something similar to Python's dis module. Actually, luac -l may help. Also, what does "what" mean in the debug info? –  Bruno Le Floch Feb 1 '12 at 14:10
    
@BrunoLeFloch a) what is Python's dis module? b) What describes where the function is defined: a "C" function or a "Lua" function (I remember seeing other things written there) –  topskip Feb 1 '12 at 14:29
    
@Patrick: sorry, the dis module is a disassembler: dis.dis(myfunction) will print (pseudo-)assembly code for myfunction. It seems luac -l does that too, but on compiled Lua files (see the well-hidden link in my previous comment), so I'm not sure whether it could be used for LuaTeX. –  Bruno Le Floch Feb 1 '12 at 14:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.