lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 2-Mar-07, at 9:27 AM, David Burgess wrote:

By no means an expert, but I have used C userdata as simple
string buffers with methods like append(), insert() and tostring() etc.
I was using these buffers to collect strings prior to compressing them
and then compressed them in place (with zlib). The resultant
compressed string was only occasionally then interned as a Lua string.

The buffer library was very simple to write and performed only the
functions that I needed for my app. The primary aim being to avoid
creating Lua strings before outputing them using ANSI IO (I also
added an io function that would allow me to write the userdata
buffer).

If the strings you're accumulating are really long, you can also
use the old trick of writing them out to a temporary file, and
then dealing with the file when you're done, either by
reading it back in pieces, or passing it to some external program,
or even just renaming it to the file you intended to create.