[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: embedded zeroes and io.lines
- From: "Brian R. Gaeke" <brg@...>
- Date: Fri, 27 Jan 2006 00:22:35 -0800
Hello,
I encountered the following behavior I didn't expect with regards
to embedded zeroes and io.lines:
% lua -v
Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio
% cat zero.lua
for line in io.lines(arg[1]) do print(tostring(string.len(line))) end
% wc zero.lua
1 7 70 zero.lua
% lua zero.lua zero.lua
69
% od -c zero
0000000 \0 \n
0000002
% wc zero
1 1 2 zero
% lua zero.lua zero
%
Specifically note the lack of output from the last command. I
feel that it should have printed 1, or 0 if string.len is supposed
to follow C-string semantics. (Is it?) More to the point, is
there a way that I can input lines from files with embedded zeroes
using io.lines or file:lines? I found that I could read the zero
using e.g. io.read(100), but I don't want to have to find the ends
of the lines myself. I am running Lua on Mac OS X 10.3.9. Thanks
for any suggestions.
-Brian Gaeke