Jump to content

C++ templates, need fresh eyes


Guppy
 Share

Recommended Posts

template <typename T,int (T::*memberFunction) (lua_State *L)>
class luaMemberFunction: public luaType{
 public:
	 luaMemberFunction(T* _objectPtr):objectPtr(_objectPtr){}
	 virtual void push() {
		 lua_pushlightuserdata( Leadwerks::Interpreter::L, objectPtr );
		 lua_pushcclosure(Leadwerks::Interpreter::L,forwarder,1);
	 }
	 T* objectPtr;
	 static int forwarder(lua_State *L){
		 //return ((T*)lua_touserdata( L, lua_upvalueindex(1) ))->*memberFunction(L);
		 return ((T*)lua_touserdata( L, lua_upvalueindex(1) )).*memberFunction(L);
	 }
};

 

called else where as

luaType temp= new luaMemberFunction<eventForwarder,&eventForwarder::testMemberFunction>(this);

 

produces this error

 

../../Source/util/lua_tablehelper.h|91|error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘&MyGUI::eventForwarder::testMemberFunction (...)’, e.g. ‘(... ->* &MyGUI::eventForwarder::testMemberFunction) (...)’|

 

As you can properly tell from the comment above I've tried both - I feel like I'm missing something obvious but after two hours of starting at the code I'm still at a loss.

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

It should be

return (((T*)lua_touserdata( L, lua_upvalueindex(1) ))->*memberFunction)(L); 

 

I'd like to thank the forum for playing the part of rubber duck ;)

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...