[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: lua_Chunkreader: tracking line numbers
- From: Juergen Fuhrmann <fuhrmann@...>
- Date: Thu, 01 Aug 2002 11:23:27 +0200 (MEST)
Hi,
Sorry for posting twice, but this came into my mind just after sending
the previous one:
How line numbers are handeled by lua_load and the chunk reader ?
Here a (fictive) example in ldf, similar things could be done with
xml.
-----------
$ldf{version={1,0}}
$x=DArray{nrow=3 ncol=5, encoding=base64}
AAAAvrBAAAAAAAC/sEAAAAAAAMCwQAAAAAAAwbBAAAAAAADCsEAAAAAAAMOwQAAAAAAAxLBA
AAAAAADFsEAAAAAAAMawQAAAAAAAx7BAAAAAAADIsEAAAAAAAMmwQAAAAAAAyrBAAAAAAADL
AAAAwM4SU0EAAAAAzxJTQQAAAEDPElNBAAAAgM8SU0EAAADAzxJTQQ==
$
for i=1,getn(x) do
print(i,x[i]}
end
-----------
If Lua encounters the error in line 8 of the file, there are three
possibilities for the line number in the error message of the Lua
parser:
a) it is indeed 8 - as one would like to have it in order to debug
the whole document
b) it is 2, and we possibly could say afterwards:
"error detected in Lua chunk started at line 7"
c) it is 1 because a chunk is handeled like a buffer.
If there is no way to track a line number by some measures in the Lua
API, I don't see how one could implement (a).
In the lua_dolines patch, for this purpose, I just added int *lineno
as a parameter to the equivalent of lua_load(). I had to change not
more than 10 lines of code in Lua-4.0.1 to get this to work (IMHO a
sign of sound quality of the code!)
Of course there might be better solutions in the API.
just my EUR 0.02
Juergen