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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:28:06+00:00 2026-06-06T14:28:06+00:00

We have class lua. In lua class there is a method registerFunc() which is

  • 0

We have class lua.

In lua class there is a method registerFunc() which is defined:

void lua::registerFun() {
    lua_register( luaState, "asd", luaApi::asd);
    lua_register( luaState, "zxc", luaApi::zxc);
}

lua_register is a built-in function from lua library: http://pgl.yoyo.org/luai/i/lua_register

it takes static methods from luaApi class as an 3rd argument.

Now some programmer wants to use the lua class, so he is forced to create his own class with definitions of the static methods, like:

class luaApi {
public:
    static int asd();
    static int zxc();
};

and now is the point. I don’t want (as a programmer) to create class named exactly “luaApi”, but e.g. myClassForLuaApi.
But for now it’s not possible because it is explicitly written in the code – in lua class:

lua_register( luaState, "asd", luaApi::asd); 

I would have to change it to:

lua_register( luaState, "asd", myClassForLuaApi::asd);

but I don’t want to (let’s assume that the programmer has no access there).

If it’s still not understandable, I give up. 🙂

Thanks.

  • 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-06T14:28:10+00:00Added an answer on June 6, 2026 at 2:28 pm

    You should be able to pass any method as the third parameter of lua_register() as long as it’s got the correct signature (int (*)(lua_State *L) a.k.a. lua_CFunction). It doesn’t have to be a static member of a class and can be any standalone function as well:

    lua_register(luaState, "myFunction", &myFunction);
    

    If this doesn’t satisfy you, you should add some bigger code snipped, e.g. your lua class. How do you add new instances of calls to lua_register()? Are you using some predefined macro? Aren’t you allowed to modify the code inside the lua class? Latter case there’s nothing you can do unless you use some preprocessor definitions or macros to “bend” your names.

    Edit:
    If you’d like the users of your lua class to be able to register their own functions, then you should just allow them to pass it as a parameter to the method (essentially the way Lua does this as well):

    void lua::registerFunction(const char *name, lua_CFunction *call) {
        lua_register(luaState, name, call);
    }
    

    If you’d like to abstract away Lua’s state object, you could as well think of doing your own wrapper calling the user’s function with a custom object (having the lua object as well as all arguments and handling return values).

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

Sidebar

Related Questions

I am embedding Lua in my C++ application. I have a class Foo which
I have class which has a method that needs to return three DataTables. I
OK so I have a C++ class that is exposed to Lua using SWIG.
I have: class BASE{ public: virtual void func1() = 0; }; Then I have
I have class Building in which i have one class member NSMutableArray *subnode.I have
I have Class which Extends View I'm able To Move one Image Over another
I have a class with a method called GetEnemiesLua. I have bound this class
I have class which implements Countable, ArrayAccess, Iterator and Serializable. I have a public
I have class A with its inner class defined A1 and class B with
I have a Lua class like below. I am using json to serialize the

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.