Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

CodeZ

Register a member function in a class

This topic is 5725 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! I have recently started to use Lua and I wonder if it is possible to register a member function in a class to Lua (or mayby a whole Class?) ? It works if I do like this:
      

class TestClass
{
public:
	TestClass();
	~TestClass();
	static int Test(lua_State* lua) { printf("hello from Class!"); return 0; }
};

lua_register( g_pkScript, "func", TestClass::Test );

  
But I don´t want to have static functions in my class. Why doesn´t this work?
  
     
static TestClass g_kApp;

class TestClass
{
public:
	TestClass();
	~TestClass();
	int Test(lua_State* lua) { printf("hello from Class!"); return 0; }
};

lua_register( g_pkScript, "func", g_kApp.Test );

  
I get this error: Compiling... test.cpp D:\Programming\MyCode\LuaTest1\test.cpp(41) : error C2664: 'lua_pushcclosure' : cannot convert parameter 2 from 'int (struct lua_State *)' to 'int (__cdecl *)(struct lua_State *)' None of the functions with this name in scope match the target type Error executing cl.exe. test.obj - 1 error(s), 0 warning(s) Thanks! [edited by - CodeZ on January 18, 2003 3:12:33 AM] [edited by - CodeZ on January 18, 2003 3:13:18 AM]

Share this post


Link to post
Share on other sites
Advertisement

  • 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!