Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8206709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:45:54+00:00 2026-06-07T08:45:54+00:00

Using the Lua C-API is there an efficient way to concatenate two LuaL_Buffer s?

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:45:56+00:00Added an answer on June 7, 2026 at 8:45 am

    You could push buf2 onto the stack first, add it to buf1 (which pops it), then push buf1 onto the stack.

    luaL_pushresult(L, &buf2); // push "b\0" onto the stack
    luaL_addvalue(&buf1); // pop that string and add it to buf1
    luaL_pushresult(L, &buf1); // push "a\0b\0" onto the stack
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using [actually learning to use] the Lua C api. I'm new to
I'm using Lua, already used Google and nothing, can't find way to get string
I'm having trouble using one Lua lib from inside another. I'm not sure about
I'm using the Lua 5.2 C API. I am trying to get a function
I am using the lua C-API to read in configuration data that is stored
My situation is that I'm using the Lua (C) API to execute a script
I'm using Luabind to bind a C++ API to Lua. I have some objects
I'm using Lua inside a C application, and I have two tables. I want
When using the Lua 5.2 API, the code below prints nil function __debug(szName, ...)
I've registered LUA api function by using: lua_register( luaState, someFunc, aaa::someFunc); this function has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.