[Dev-luatex] "error" in LuaTeX and Lua

Jonathan Sauer Jonathan.Sauer at silverstroke.com
Wed Apr 30 09:54:18 CEST 2008


Hello,

> > [setting \directlua's chunk name]
> > 
> > This allows you to do stuff like this:
> > 
> >     \directlua name {\jobname-\the\inputlineno} 0 {error('test')}
> 
> Great! Thanks! I'll try it this evening (your example is especially
> intriguing).

Well, I tried it, and apart from some minor nitpicks it works
perfectly, as does <error>'s stack traceback:

--------------------------------------------------------------

%&luatex


% \directlua0{error()} % A
% \directlua0{error('')} % B

\directlua name{Test} 0{ % C
	function a() b() end
	function b() c() end
	function c() d() end
	function d() error('') end
	
	a()
}


\end

--------------------------------------------------------------

(A) results in:

This is LuaTeX, Version snapshot-0.25.3-2008042918 (Web2C 7.5.6)
(Error2.tex
! LuaTeX error .
l.4 \directlua0{error()}
                         % A
? 


(B) results in:

This is LuaTeX, Version snapshot-0.25.3-2008042918 (Web2C 7.5.6)
(Error2.tex
! LuaTeX error [string "\directlua0"]:1: 
stack traceback:
	[C]: in function 'e
rror'
	[string "\directlua0"]:1: in main chunk.
l.5 \directlua0{error('')}
                           % B
? 


Of course, (A) is not a really relevant case, since no-one in their 
right mind would call <error> without an appropriate message. Still, 
it is a bit puzzling why there is no traceback.

Also note how the traceback is wrapped in a slightly weird way. Most 
likely this is because it is written using <texio.write>, which does 
not reset its line length counter at a \r.

This is even more prominent in case (C):


This is LuaTeX, Version snapshot-0.25.3-2008042918 (Web2C 7.5.6)
(Error2.tex
! LuaTeX error [string "Test"]:1: 
stack traceback:
	[C]: in function 'error'
	
[string "Test"]:1: in function 'd'
	[string "Test"]:1: in function 'c'
	[string
 "Test"]:1: in function 'b'
	[string "Test"]:1: in function 'a'
	[string "Test"
]:1: in main chunk.
l.14 }
      
? 

Also, I would have expected the chunk name to be only 'Test'. IMO the
current form is a bit confusing. OTOH, this is also the way Lua
handles chunk names passed to <loadstring>.

Nevertheless (even though I don't know your policy on modifying library
code), I have prepared a patch for lobject.c that changes the chunk's
name (it still encloses it in [ and ] so it can be distinguished from
a 'real' Lua file):

200c200
<     else {  /* out = [string "string"] */
---
>     else {  /* out = [string] */
202c202
<       bufflen -= sizeof(" [string \"...\"] ");
---
>       bufflen -= sizeof(" [...] ");
204c204
<       strcpy(out, "[string \"");
---
>       strcpy(out, "[");
211c211
<       strcat(out, "\"]");
---
>       strcat(out, "]");


This results in:

This is LuaTeX, Version snapshot-0.25.3-2008042921 (Web2C 7.5.6)
(Error2.tex
! LuaTeX error [Test]:1: 
stack traceback:
	[C]: in function 'error'
	[Test]:1:
 in function 'd'
	[Test]:1: in function 'c'
	[Test]:1: in function 'b'
	[Test]:
1: in function 'a'
	[Test]:1: in main chunk.
l.14 }
      
? 

What do you think?


Jonathan



More information about the dev-luatex mailing list