lua_bufflib

A library for string buffers in Lua

$ luarocks install lua_bufflib

A library for string buffers in Lua.

The buffer code in this library is largely adapted from Lua 5.2's luaL_Buffer code.
The main difference is that Buffers store their contents in the registry instead of the stack when their length exceeds LUAL_BUFFERSIZE.
This prevents the C char array holding the current contents from being garbage collected until a larger array is required or the Buffer is reset or garbage collected.
You don't need to know any of this to use the library, it's just extra information for people curious about the implementation.

Just like regular strings in Lua, string buffers can contain embedded nulls (\0).

Similar to Lua's string library, most Buffer methods can be called as `buff:method(...)` or `bufflib.method(buff, ...)` (where `buff` is a Buffer).
Note that not all methods use the same name in the Buffer metatable and the `bufflib` table.
The primary examples of this are the metamethods, which use the required metamethod names in the metatable and more descriptive names in the `bufflib` table (e.g. the `__len` metamethod is the same as `bufflib.length`).

Buffers define metamethods for length (#), concatenation (..) and tostring(). See the documentation of each metamethod for details.

Versions

0.2.1-16 years ago181 downloads
0.2.0-16 years ago83 downloads
0.0.1-16 years ago19 downloads

Dependencies

lua >= 5.1, < 5.3

Manifests