Exploring the Lua innards of ConTeXt: showtable
Hi all, ConTeXt mkiv stores all sorts of things in Lua tables, but 'what goes where' does not tend to be documented. So here is a function to print out a table's contents to get something like the following excerpt. The excerpt is from the output of `userdata.showtable(structures.lists)` in a document with three \placefigures and one \placeformula. Note the reference in T.cached.1.references.reference, and the caption in T.cached.1.titledata.title (T stands for the table yone passed to showtables); and note how the tables of figures 2 and 3 are not printed, because they follow the same pattern as table 1. (You can tell showtable to print everything, natch.) T.addto : function: 0xa4c8818 T.analyze : function: 0xb1c27b0 T.cached : table: 0xb1c2240 T.cached.1 : table: 0xc3f7b18 T.cached.1.metadata : table: 0xc3f7d58 T.cached.1.metadata.kind : float T.cached.1.metadata.name : figure T.cached.1.prefixdata : table: 0xc3f7c68 T.cached.1.prefixdata.connector : . T.cached.1.prefixdata.prefix : no T.cached.1.references : table: 0xc3f7ba8 T.cached.1.references.reference : ref:asdf T.cached.1.titledata : table: 0xc3f7b40 T.cached.1.titledata.title : caption 1 T.cached.2 : table: 0xc467bb8 (like T.cached.1) T.cached.3 : table: 0xc4731a8 (like T.cached.1) T.cached.4 : table: 0xc47c988 T.cached.4.metadata : table: 0xc47d628 T.cached.4.metadata.kind : formula T.cached.4.metadata.name : formula (You can't see it in this e-mail, but the colons of entries in the same subtable nicely line up with each other.) Usage: put showtable.lua in your working directory and run the following code: \starttext % \placefigure[][ref:asdf]{caption 1}{picture 1} \startluacode require('showtable') userdata.showtable(structures.lists) \stopluacode \stoptext Extra options can be passed as part of an options table. (This allows overriding one option without respecifying the others.) userdata.showtable( structures.lists, { everything=true, -- descend even into similar-looking siblings tablename='S.L' } ) Output is printed to the terminal, alas, because I couldn't discover how to print to the log. Anybody know anything about this? Hopefully this may be useful to someone, next time they they're hunting for something in the bowels of ConTeXt. Interesting tables to look at: * userdata.showtable(commands) contains a great miscellanea of helper commands * userdata.showtable(context) also contains a great miscellanea of commands * userdata.showtable(tex) seems to show lua access functions to some plain tex stuff * userdata.showtable(lxml) gives a list of lxml-related functions Cheers, Sietse
On 17-9-2012 17:47, Sietse Brouwer wrote:
Hi all,
ConTeXt mkiv stores all sorts of things in Lua tables, but 'what goes where' does not tend to be documented. So here is a function to print out a table's contents to get something like the following excerpt.
Keep in mind that many datatables are not frozen in stone i.e. their structure might change at some point (I still need to finish cleaning up some structure related code, after that most will stay as it is). In case you don't this one: context s-inf-03.mkiv It reports some info about what sits in a table (d means data).
The excerpt is from the output of `userdata.showtable(structures.lists)` in a document with three \placefigures and one \placeformula. Note the reference in T.cached.1.references.reference, and the caption in T.cached.1.titledata.title (T stands for the table yone passed to showtables); and note how the tables of figures 2 and 3 are not printed, because they follow the same pattern as table 1. (You can tell showtable to print everything, natch.)
T.addto : function: 0xa4c8818 T.analyze : function: 0xb1c27b0 T.cached : table: 0xb1c2240 T.cached.1 : table: 0xc3f7b18 T.cached.1.metadata : table: 0xc3f7d58 T.cached.1.metadata.kind : float T.cached.1.metadata.name : figure T.cached.1.prefixdata : table: 0xc3f7c68 T.cached.1.prefixdata.connector : . T.cached.1.prefixdata.prefix : no T.cached.1.references : table: 0xc3f7ba8 T.cached.1.references.reference : ref:asdf T.cached.1.titledata : table: 0xc3f7b40 T.cached.1.titledata.title : caption 1 T.cached.2 : table: 0xc467bb8 (like T.cached.1) T.cached.3 : table: 0xc4731a8 (like T.cached.1) T.cached.4 : table: 0xc47c988 T.cached.4.metadata : table: 0xc47d628 T.cached.4.metadata.kind : formula T.cached.4.metadata.name : formula
(You can't see it in this e-mail, but the colons of entries in the same subtable nicely line up with each other.)
Usage: put showtable.lua in your working directory and run the following code:
\starttext % \placefigure[][ref:asdf]{caption 1}{picture 1} \startluacode require('showtable') userdata.showtable(structures.lists) \stopluacode \stoptext
Extra options can be passed as part of an options table. (This allows overriding one option without respecifying the others.) userdata.showtable( structures.lists, { everything=true, -- descend even into similar-looking siblings tablename='S.L' } )
Output is printed to the terminal, alas, because I couldn't discover how to print to the log. Anybody know anything about this?
commands.writestatus("mylog",str) or: local myreporter = logs.reporter("tables") myreporter(....)
Hopefully this may be useful to someone, next time they they're hunting for something in the bowels of ConTeXt. Interesting tables to look at: * userdata.showtable(commands) contains a great miscellanea of helper commands
the commands namespace is used for commands that pipe something to tex and/or are calles in a command at the tex end
* userdata.showtable(context) also contains a great miscellanea of commands
this is the print-to-tex namespace
* userdata.showtable(tex) seems to show lua access functions to some plain tex stuff * userdata.showtable(lxml) gives a list of lxml-related functions
Cheers, Sietse
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
-- ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (2)
-
Hans Hagen
-
Sietse Brouwer