I'm trying to write a thin wrapper around AngelScript. I'm having trouble figuring out how to wrap around a particular struct.
Here is the struct definition for the struct I want to wrap, asSMethodPtr
:
template <int N>
struct asSMethodPtr
{
template<class M>
static asSFuncPtr Convert(M Mthd)
{
// This version of the function should never be executed, nor compiled,
// as it would mean that the size of the method pointer cannot be determined.
int ERROR_UnsupportedMethodPtr[N-100];
asSFuncPtr p;
return p;
}
};
Here is the definition for asSFuncPtr
:
struct asSFuncPtr
{
union
{
char dummy[25]; // largest known class method pointer
struct {asFUNCTION_t func; char dummy[25-sizeof(asFUNCTION_t)];} f;
} ptr;
asBYTE flag; // 1 = generic, 2 = global func
};
Here is the code I've found (taken from the AngelBinder library) that allows me to 'wrap' it:
template<typename R> ClassExporter& method(std::string name, R (T::*func)())
{
MethodClass mthd(name, Type<R>::toString(), asSMethodPtr< sizeof( void (T::*)() ) >::Convert( AS_METHOD_AMBIGUITY_CAST( R (T::*)()) (func) ));
this->_methods.push(mthd);
return *this;
}
Unfortunately, I have no idea what this code is doing...
What is T::*
supposed to do? A pointer to the class type?
What is R (T::*func)()
?
Any help appreciated...