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 8466647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:24:10+00:00 2026-06-10T15:24:10+00:00

My game engine pushes a value on to the lua stack as a parameter

  • 0

My game engine pushes a value on to the lua stack as a parameter to a function and then invokes it using lua_pcall. The lua code will run and call additional lua functions. Eventually this lua code will invoke a C function. Is it possible for this function to retrieve the value that was originally pushed on to the stack?

Its like this:

<engine function A>
  pushes parameter value X on to stack for lua
<lua func>
<lua func>
<lua func>
<engine function B>
  can I extract the values X that was pushed by function A here?
  • 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-10T15:24:12+00:00Added an answer on June 10, 2026 at 3:24 pm

    Yes, with a combination of getinfo, getlocal and getupvalue you can get all that information (you can even change those values using set* functions).

    Here is a fragment from MobDebug that returns stack information along with a table of locals and upvalues at each level. The variables at each level will be indexed in the same order they appear in the code (starting from parameters). For each get* function you can use their C equivalents (lua_getinfo, lua_getlocal, and lua_getupvalue), but the logic should be exactly the same.

    local function stack(start)
      local function vars(f)
        local func = debug.getinfo(f, "f").func
        local i = 1
        local locals = {}
        while true do
          local name, value = debug.getlocal(f, i)
          if not name then break end
          if string.sub(name, 1, 1) ~= '(' then locals[name] = {value, tostring(value)} end
          i = i + 1
        end
        i = 1
        local ups = {}
        while func and true do -- check for func as it may be nil for tail calls
          local name, value = debug.getupvalue(func, i)
          if not name then break end
          ups[name] = {value, tostring(value)}
          i = i + 1
        end
        return locals, ups
      end
    
      local stack = {}
      for i = (start or 0), 100 do
        local source = debug.getinfo(i, "Snl")
        if not source then break end
        table.insert(stack, {
          {source.name, source.source, source.linedefined,
           source.currentline, source.what, source.namewhat, source.short_src},
          vars(i+1)})
        if source.what == 'main' then break end
      end
      return stack
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a game engine in C++ using Lua for NPC behaviour. I
I'm using a game engine that allows you to program in Lua. The game
We are using the Love2d Lua game engine that exposes a graphics api to
I am making a game engine using HTML5 canvas, and I have decided to
I'm making a game engine for mobile devices. I want to compile my code,
I have small game engine written in c++. I'm considering using some features of
I have an underlying ruby game-engine code and I want to use the web
I'm creating a game engine using wxWidgets and OpenGL. I'm trying to set up
I'm writing a game engine using pygame and box2d, and in the character builder,
i'm using cocos2d game engine for python. And i read api document but i

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.