使用Lua的C-API是有连接两个LuaL_Buffer
秒的有效方法?我宁愿不做任何不必要的memcopys,并想要luaL_pushresult()
消耗的结果。该缓冲区包含嵌入零,所以我不能将它们转换为字符数组,并使用luaL_addstring()
。修改任一缓冲区是可以接受的。如何连接两个Lua luaL_Buffer ojbects?
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