[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: io.lines() behaviour on \0 characters
- From: Ico <lua@...>
- Date: Wed, 28 Oct 2009 11:23:33 +0100
Hello,
I'm trying to use io.lines() to read lines from a file which contains \0
characters. This seems to fail, probably because of the fgets() used in
iolib.c:read_line().
Because - unlike C strings/char arrays - Lua strings are 8-bit safe, the
expected behaviour for me was for io.lines() to simply handle the \0's
as regular characters.
local fd = io.open(os.tmpname(), "r+")
fd:write("one\0one\n")
fd:write("two\0two\n")
fd:write("three\0three\n")
fd:seek("set", 0)
i = 0
for l in fd:lines() do
i = i + 1
print(i, l)
end
I would expect the above to show
1 one<\0>one<\n>
2 two<\0>two<\n>
3 three<\0>three<\n>
instead, it returns
1 onetwothree<\n>
(control characters enclosed in <> by me)
I did not find any references in the documentation about how iolib is
supposed to handle zeros. Is the behaviour I see intented, or more of an
side effect of the usage of C-strings in the implementation of
io.lines() ?
--
:wq
^X^Cy^K^X^C^C^C^C