Re: [NTG-context] Trying to understand this ctxlua error

Gerben Wierda schrieb am 06.04.2020 um 00:41:

I got this error after I had changed some lua code:


tex error       > tex error on line 272 in file archimate-lua.new: ! Undefined control sequence

warnIfVerbose( "Breaking off the processing of node %s\nNo

l...eak           xsi:type", node) \luat_start_lua_code_indeed ...ormalexpanded {\endgroup \noexpand \directlua {#1         }}
l.272 \stopluacode

<empty file>


The control sequence at the end of the top line of your error message was never
\def'ed. You can just continue as I'll forget about whatever was undefined.


I have been looking at that code for over two hours, not seeing anything wrong with it. But I’ve now finally found the culprit and I still do not get it.

The culprit was:


warnIfVerbose( "Breaking off the processing of %s\n No elementRef", node)

The problem goes away when I use:


warnIfVerbose( "Breaking off the processing of %s\nNo elementRef", node)

(I don’t want the line after the node is printed to begin with a space).


But the lack of space between \n and N kills lua (apparently). For completeness (as string.format and texio.write_nl are also in play):

function warnWithLabelIfVerbose( str, ... )
if verboseProgram then
texio.write_nl( str .. string.format(...))
end
end

function warnIfVerbose( ... )
warnWithLabelIfVerbose("-----> ", ...)
end


Is this a lua bug? A ConTeXt bug? Expected behaviour? And if so, why is reported that on line 272 (where \stopluacode is) is the error? Or is the error message indeed helpful and do I just lack the know how to interpret it?

ConTeXt expands TeX commands in a luacode-environment
and when you have \n followed by text you create a new
command with starts with \n but since it isn't defined
you get a error message.

In the example below the commented block produces
the same error message as you get.

\starttext

%\startluacode
%print("text\ntext")
%\stopluacode

\startluacode
print("text\n text")
\stopluacode

\stoptext

Wolfgang
___________________________________________________________________________________