15

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

1 Answer 1

15

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" )
4
  • 1
    there is also "lastlinedefined", so you could potentially print a portion of the source file .. Commented Feb 1, 2012 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? Commented Feb 1, 2012 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
    Commented Feb 1, 2012 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. Commented Feb 1, 2012 at 14:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .