[NTG-context] Return value of context call

Taco Hoekwater taco at elvenkind.com
Mon Jul 5 09:41:39 CEST 2010


On 07/04/2010 07:39 PM, Marco wrote:
> Hi,
>
> when there's a mistake in the context code then the context call
> returns »1«. When there's a mistake in the metapost code then the
> context call returns »0«.
>
> This is annoying for me, since I use the return value as indicator for
> my pdf reader to refresh. This seems like a bug to me. Is there a
> workaround?

Like this maybe, this converts metapost errors into a series of tex
errors:

\startluacode
function report_mplib_error (...)
     local v = string.format(...)
     tex.sprint(tex.ctxcatcodes,"\\errmessage{")
     tex.sprint(tex.vrbcatcodes,v)
     tex.print(tex.ctxcatcodes,"}")
end

function metapost.reporterror(result)
     if not result then
         report_mplib_error("mp error: no result object returned")
     elseif result.status > 0 then
         local t, e, l = result.term, result.error, result.log
         if t and t ~= "" then
             report_mplib_error("mp terminal: %s",t)
         end
         if e then
             report_mplib_error("mp error: %s",(e=="" and "?") or e)
         end
         if not t and not e and l then
             metapost.lastlog = metapost.lastlog .. "\n" .. l
             report_mplib_error("mp log: %s",l)
         else
             report_mplib_error("mp error: unknown, no error, terminal 
or log messages")
         end
     else
         return false
     end
     return true
end

\stopluacode


More information about the ntg-context mailing list