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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:01:28+00:00 2026-06-03T18:01:28+00:00

I want to setup a couple of functions in Lua for scripters but when

  • 0

I want to setup a couple of functions in Lua for scripters but when those functions are invoked, I’d like them to actually invoke a single function with a parameter that I define. This might look like:

Lua:

    foo1()
    foo2()

C++:

int myFunction( lua_State * context )
{
    int numArgs = lua_gettop( context );
    int topOfStack = -3;
    bool lightUserDataFlag = lua_islightuserdata( context, topOfStack );

    if( lightUserDataFlag )
    {
    }
}

}

So I am a little confused on the setup. I am trying to register the callback with a param. This is what I have so far and there is something that is not saving the param with the function registration; it seems to only save the last param I add.

void setupCallback()
{
    lua_register( context, "foo1", Callback);
    lua_pushlightuserdata( context, &value[0] );
    lua_register( context, "foo2", Callback);
    lua_pushlightuserdata( context, &value[1] );
}

When lua invokes my callback, I always see the value[1], never the value[0]. I played with the notion of registering the callback and then adding a table, but I’m not sure that this will get me any further.

As to the why: I am trying to abstract function names to make writing code for our lua programmers easier, but those simply need to translate into the same parameterized function. Think of it add changing settings by passing a single param, but naming that differently.

Thoughts?

  • 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-03T18:01:31+00:00Added an answer on June 3, 2026 at 6:01 pm

    You likely want to attach those context values as upvalues of your function. Take a look at lua_pushcclosure().

    Incorporating Mickey Kawick’s comment:

    int Callback (lua_State *context)
    {
        int val= lua_tointeger( context, lua_upvalueindex(1) );
        cout << val << endl;
        ...
    } 
    
    void setup()
    {
        lua_pushnumber( context, 3 );
        lua_pushcclosure( context, Callback, 1 );
        lua_setglobal( context, "foo1" );
    
        lua_pushnumber( context, 42 );
        lua_pushcclosure( context, Callback, 1 );
        lua_setglobal( context, "foo2" );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want a setup like this: +- /ApplicationFolder -- App.exe -- Core.dll -- AnotherShared.dll
I want to setup a serialized task queue using NSOperationQueue but I'm a little
I want to setup local domains like sub1.mydomain.dev and www.mydomain.dev on my local IIS
I want to setup values for a combobox in vb.net through code. But I
I want to setup jetty with jetty-blazeds extension. Everything looks fine but when I
I want to have a setup like this: <div id=block> <div class=btn>2</div> <div class=btn>1235e</div>
This is a single question, but with a couple of sub questions. I am
I want to setup a simple site and I don't have any web development
I want to setup a Method dispatch table and I am wondering if it
I want my setup.py to do some custom actions besides just installing the Python

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.