Given that the LuaL_Buffer object: "During its normal operation, a string buffer uses a variable number of stack slots", I don't understand how two luaL_Buffer objects can be used at the same time. Will they each assume the state of the stack is as they require? In other words, one buffer might put something on the top of the stack and expect it to be there in some future call, while the same being true for another buffer? Is it not possible to work with two LuaL_Buffers at the same time?
Here is an example of some operation that requires two buffers at the same time. It seems to work for small tests, but don't know if it will stand up in production.
int res;
char *p;
size_t dlen;
struct luaL_Buffer src;
struct luaL_Buffer dst;
luaL_buffinit(L, &src);
luaL_buffinit(L, &dst);
luaL_addvalue(&src);
// .. grow/mod the src buffer in various ways
p = luaL_prepbuffsize(&dst, dlen);
res = my_uncompress((Byte *)(src.b), src.n, (Byte *)p, &dlen);
luaL_addsize(&dst, dlen);
// .. do things to the dst buffer ..
where my_uncompress
is wrapper to a zlib method