[NTG-context] Looking for a way to use lua to output console/debug messages from MetaPost instead of 'show'

Gerben Wierda gerben.wierda at rna.nl
Mon May 18 14:46:14 CEST 2020

I often need some debugging info to find out what is going on in my METAPOST code (as I often do not have exact knowledge of what some things do). MetaPost’s ‘show’ command has limited formatting functionality (e.g. I would like to add a number as a string to a show message instead of putting it out as number and let ‘show' make a lot of lines out of it). 

I would like to instead use a lua function and I think I recall having seen somewhere the use of a call like lua( ….) or lua.foo.bar() in a MetaPost/MetaFun/LMTX example but I cannot find it anymore. 

Is it possible to do a lua() call from within MetaPost within LMTX and if so, what is the way to do it? This below is the state of my misguided attempts:

function warnWithLabelIfVerbose( str, ... )
  texio.write_nl( str .. string.format(...))

%def somefunction ( expr str, number) =
%  lua.warnWithLabel( "LABEL: ", "%s %d", str, number);

lua.texio.write_nl( "HELLO!"); % This works
%lua.texio.write( "HELLO!\%n"); % This doesn't
%string outs; outs := lua.string.format( "HELLO! \%s \%0.3f", "aap", 12.6);
%somefunction( "aap", 12.6);


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20200518/efd44f4b/attachment.htm>

More information about the ntg-context mailing list