Jump to content
  • Advertisement
Sign in to follow this  
noaktree

lua_register & C++ member functions

This topic is 5047 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone // Create a class with a member function Class Stomach { public: int luaDigest(lua_State *luaVM); }; ... // Define member function ... // Create a stomach obj in the main somewhere Stomach aStmch; // Register member function (or try anyway) lua_register(g_luaVM, "Digest", aStmch.Digest); ... When this is compiled I get this error: Source\Main.cpp(166) : error C2664: 'lua_pushcclosure' : cannot convert parameter 2 from 'int (lua_State *)' to 'lua_CFunction' None of the functions with this name in scope match the target type How can I register a member function of a class to lua??

Share this post


Link to post
Share on other sites
Advertisement
You cannot treat a non-static member-function pointer as a non-member-function pointer, and you certainly cannot make a member-function "closure" in C++, as you are trying to do here. You could make a global or static member function that turns around and calls the appropriate function. Alternatively, you could look into LuaBind, which will do much of this stuff for youl

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!