creating an angelscript asSMethodPtr (without the asMETHOD macro)

219 Views Asked by At

I'm trying to get a more dynamic workflow with Angelscript happening, where I don't rely on the asMETHOD macro to pass class/method information to Angelscript.

However, I'm unable to get it to work so far.

Here's some structs I've defined (with which to setup Class and Method data):

struct Class {
std::string name;
std::string factorySignature;
void* pointer;
void* factoryPointer;
void* addRefMethodPointer;
void* releaseRefMethodPointer;
};


struct Method {
std::string name;
std::string signature;
void* pointer;
};

Later on, I try to create an asSMethodPtr struct object using a Class struct object I had created earlier. This is what I do:

auto methodPtr = asSMethodPtr<sizeof(void (classObject.pointer)())>::Convert((void (classObject.pointer)())(classObject.addRefMethodPointer));

Unfortunately, this results in the following errors:

src/common/as_wrapper/AngelScript.cpp:98:66: error: void value not ignored as it ought to be
src/common/as_wrapper/AngelScript.cpp:98:68: error: template argument 1 is invalid
src/common/as_wrapper/AngelScript.cpp:98:107: error: void value not ignored as it ought to be
src/common/as_wrapper/AngelScript.cpp:98:142: error: unable to deduce ‘auto’ from ‘<expression error>’

Anyone have any ideas? I've afraid this asSMethodPtr struct is pushing the limits of my C++ abilities...

1

There are 1 best solutions below

0
On

Pointer to member functions have the format of return_type (class_name::*)(parameter_list) const-volatile_qualifiers. The argument you are trying pass to sizeof is composed of what looks like a local variable and a member variable and is ill-formed. It should look like the following

sizeof(void (Class::*)())

The argument you are passing to Convert is also ill-formed. You need to take the member function by address using the & address-of operator. Another problem is that addRefMethodPointer is a member variable not a function so the cast will fail.

struct Class
{
    void SomeMemberFunction() {}
};

(void (Class::*)())(&Class::SomeMemberfunction)