Using the Lua C-API is there an efficient way to concatenate two LuaL_Buffers? I’d rather not do any unnecessary memcopys and want the result consumed by luaL_pushresult(). The buffers contain embedded zeros so I can’t convert them to char arrays and use luaL_addstring(). It is acceptable to modify either buffer.
luaL_Buffer buf1;
luaL_Buffer buf2;
luaL_buffinit(L, &buf1);
luaL_buffinit(L, &buf2);
luaL_addchar(&buf1, "a");
luaL_addchar(&buf2, "b");
luaL_addchar(&buf1, "\0");
luaL_addchar(&buf2, "\0");
luaL_pushresult(L, Want_this(&buf1, &buf2) ); // "a\0b\0" is now the Lua string
// at the top of the stack
You could push
buf2onto the stack first, add it tobuf1(which pops it), then pushbuf1onto the stack.