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:

\startluacode
function warnWithLabelIfVerbose( str, ... )
  texio.write_nl( str .. string.format(...))
end
\stopluacode

\startMPdefinitions{doublefun}
%def somefunction ( expr str, number) =
%  lua.warnWithLabel( "LABEL: ", "%s %d", str, number);
%enddef;
\stopMPdefinitions

\startMPpage[instance=doublefun]
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);
\stopMPpage

Thx,

G