Archived

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

CodeZ

Register a member function in a class

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