[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] Penlight 0.9.8
- From: David Manura <dm.lua@...>
- Date: Tue, 29 Nov 2011 19:25:00 -0500
On Tue, Nov 29, 2011 at 1:21 PM, Petite Abeille
> The extensive Penlight treatise mentions "File-style I/O on Strings". Which is nice.
> Would anyone have the reverse? String-style methods on Files?
> local aFile = io.open( 'test.txt', 'rb' )
> if aFile:find( 'foo', 1, true ) do
> In other words, string methods  working in terms of a file object? :)
I once ported the Lua 5.1 string library to pure Lua . Here,
strings are represented as Lua tables of characters, and those tables
can be proxy tables to other things like files (see "filearray.lua"
The caveat is that this is a straight line-by-line port of the C code
and therefore probably not the most efficient it could be. So, I'm
not sure if this would be of any practical use to anyone. In most
cases you can probably instead just read the entire file into a string
in memory and use the regular string library or read chunk-by-chunk
and do string matching on each individual chunk (appropriately taking
boundaries into account). Another approach may be to use some
memory-mapped file support on the OS.