I am using the variadic call pattern shown here. It works fine for ordinary C functions. But I want to use it with a member function and a tuple that explicitly has an instance pointer as the first argument.
I tried something like this:
template<typename Ret, typename C, typename...Args>
int methodWrapper(const string& name, Ret (C::*func)(Args...), lua_State* L)
{
return wrap<Ret,C*,Args...>::wrapFunc(name, func, L);
}
But it fails to convert the pointer type:
cannot initialize a parameter of type 'void (*)(Object *, float, float)' with an lvalue of type 'void (Object::*)(float, float)'
In this case, the wrap function is templated, so the type of the pointer has to match exactly.
template<typename Ret, typename...Args>
struct wrap{
static int wrapFunc(const string& name, Ret (*func)(Args...), lua_State* L)
{
...
}
};
How to I explicitly convert a member function pointer into an ordinary function pointer that takes the this pointer as its first argument?
EDIT: for those that have linked me to this question, it is not the same. I do not have to pass a plain C function pointer to an existing API with a specific interface. And I am not trying to bind a member function to a specific object. This question also does not deal with variadic call or tuples.