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

  • SEARCH
  • Home
  • 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 553761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:38:20+00:00 2026-05-13T11:38:20+00:00

Currently I’m building my own script VM manager class in C++. I have no

  • 0

Currently I’m building my own script VM manager class in C++. I have no problems with any of the Lua & Lua C or C++ stuff, but the one section that confuses me is when to use lua_pop and when to use lua_remove.

From what I understand, lua_pop is to remove multiple values(on the stack) from the top down, eliminating data that is no longer needed, where as lua_remove is for removing a single value from any arbitrary, valid stack index (basically what the Lua manual says for both :P).

But I’ve noticed certain segments of code scattered around the web that intermix lua_pop and lua_remove, but when I tried to use lua_pop instead of lua_remove where the call just removed the top stack element, I ran into problems. So would it be possible to get a definitive example or explanation on how and when to use these two functions correctly, as well as relative speed & efficiency for these two? I assume lua_pop is faster than lua_remove, which is one of the reasons why I want to use lua_pop as much as possible, apart from coding ‘correct code’.

  • 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-05-13T11:38:20+00:00Added an answer on May 13, 2026 at 11:38 am

    A typical example of lua_remove is accessing tables. Snippets from Lua reference manual.

    lua_getfield(L, LUA_GLOBALSINDEX, "t");   /* table to be indexed */
    lua_getfield(L, -1, "x");        /* push result of t.x (2nd arg) */
    lua_remove(L, -2);                  /* remove 't' from the stack */
    

    lua_getfield pushes t[x] on the stack. You no longer need t, so you remove it.

    A typical example of lua_pop is iterating over a table.

    lua_pushnil(L);  /* first key */
    while (lua_next(L, t) != 0) {
        /* uses 'key' (at index -2) and 'value' (at index -1) */
        /* do whatever you like with the key and the value */
    
        lua_pop(L, 1);
    }
    

    After you are done with a single iteration, you need to have the key on top of the stack, so that lua_next knows which key/value pair comes next. You need to remove the value, which is on top of the stack.

    It’s not a definitive example. In Lua you do whatever works for you. Always keep in mind what’s on your lua_State stack, and you’ll be fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I have: <html> <div class=yes1><span><img src=img></span></div> </html> <script> var x = ='yes1' var
Currently, I have a log file of messages in one table in a MySQL
Currently I have a web service, which loads up any plugins located within its
Currently I have this: var x = Convert.ToString(dateTimePicker2.Value.Subtract(dateTimePicker1.Value)); int xDays = Convert.ToInt32(x.Substring(0,1)); But it's
Currently, I have the following class: #btnHelp { background: url(images/btnHelp.png) center no-repeat, -webkit-gradient(linear, left
Currently I'm starting a new Activity and calling finish on a current one. Is
Currently, I'm working on a project where I have a server - client relationship
Currently I have 2 ways of displaying images in a cell, which way will
Currently I have this code: <?php echo '<meta name=robots content=noindex>'; $arr = json_decode(file_get_contents(http://media1.clubpenguin.com/play/en/web_service/game_configs/ paper_items.json),true);
Currently i have a node.js and socket.io application in development on my local machine

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.