[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Reading a zero-terminated string
- From: David Given <dg@...>
- Date: Mon, 09 Jun 2008 13:43:23 +0100
Enrico Colombini wrote:
[...]
Did I miss a simpler and/or cleaner (pure-Lua) way to read a
0-terminated string into a Lua string?
You could read the whole file into a single Lua string (which can handle
embedded \0 characters) and then use patterns to extract the substrings.
"(.*)%z()" should return a string and the position of the next one.
If you didn't want to read the entire file, you could efficiently do it
in big chunks of 16kB or so, but then you'd end up with having to deal
with strings overlapping chunks --- not hard, but irritating.
--
David Given
dg@cowlark.com