lua-users home
lua-l archive

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

hi dear list :)

I have written a module named lbuffer[1] for Lua in holidays. it
provides the mutable string features. it's also in very early period:
no doc, no makefile :(  I write this module is just to prevent useless
memory copies in string operations. it supports pack/unpack feature,
subbuffer feature, many modify operations and a lot of compatible
functions. below is the readme file of project.


 lbuffer - a mutable string support to lua

lbuffer is a C module for lua, it provides mutable string feature to
lua language[1]. it has all routines from lua's string module, except
pattern match, reverse and byte-code dump. and add several modify
functions. it provides:
    * change the value of buffer without copy it.
    * a pair of full feature pack/unpack functions.
    * get a subbuffer from the origial buffer, and the changes to
      subbufer will affects origial buffer.

and you can add lbuffer.h and recompile the other C module to get full
lbuffer compatible with other lua module. just add:
-DLB_OVERLOAD_LUA_API -include lbuffer.h

when you compile other Lua C modules (using gcc). e.g. if you compile
a lbuffer compatible md5[2] module, you can use them together like

    require 'buffer'
    require 'md5'
    print(md5.sumhexa(buffer "hello world"))



compile it just like other lua module. in *nix, just:
gcc -shared *.c -llua51

and in Windows using MinGW, just:
gcc -mdll -DLUA_BUILD_AS_DLL -I/path/to/lua/include *.c
/path/to/lua51.dll -o buffer.dll

and in Windows using MSVC, just create a Win32/DLL Project, and add
all .c and .h files to project, set output name to buffer.dll and
compile it.

if you want subbuffer feature, you need define a macro named
LB_SUBBUFFER, because subbuffer will slow the memory realloc function
in *all* buffers.


    -- main usage see test.lua
    require 'buffer'
    local b = buffer "hello"
    b:append "world"
    b:sub(6,5):assign " "
    assert(b :eq "hello world")