And to answer my own question, yes it seems to work with return values. So I take that the only thing that matters in this case is the syntax string?
So, to document this whole thing (and hopefully get feedback if you see anything potentially bad) this is what I am doing. In the dll, in a header I have to the following helpers:
class ScriptMethodAddressDummy { };
typedef void(ScriptMethodAddressDummy::*ScriptMethodAddress)();
struct ScriptMethodPointer
{
template <typename T>
ScriptMethodPointer(T& delegate)
{
delegateObjectAddress = &delegate;
methodAddress = reinterpret_cast<ScriptMethodAddress>(&T::operator());
}
void* delegateObjectAddress;
ScriptMethodAddress methodAddress;
};
Except for the dummy suggested by Andreas I made a small class that can be passed any fastdelegate of any kind and it extracts the needed addresses out of it. My registration function (also on the dll side) now looks like this:
void ScriptedComponent::registerScriptMethod(asIScriptEngine* scriptEngine, const char* typeName, const char* scriptSyntax, const ScriptMethodPointer& methodPointer)
{
int32_t r = scriptEngine->RegisterObjectMethod(typeName, scriptSyntax, asSMethodPtr<sizeof(ScriptMethodAddress)>::Convert(methodPointer.methodAddress), asCALL_THISCALL_OBJLAST, methodPointer.delegateObjectAddress);
assertf(r >= 0, "Failed to register method \"%s\" of type \"%s\" with the script engine.", scriptSyntax, typeName);
}
Does that look OK? Particularily the asSMethodPtr part.
On the exe side, let's say I have the following method I want to extract:
void TankAIDrivingBehavior::moveToGameObject(StringHash gameObjectNameHash);
I first make the proxy and delegate.
namespace
{
void moveToGameObjectProxy(StringHash gameObjectNameHash, void* self)
{
static_cast<TankAIDrivingBehavior*>(self)->moveToGameObject(gameObjectNameHash);
}
FastDelegate2<unsigned int, void*, void> moveToGameObjectDelegate = &moveToGameObjectProxy;
}
Then all I need to do is register the method with the following code:
ScriptedComponent::registerScriptMethod(scriptEngine, "TankAIDrivingBehavior", "void moveToGameObject(uint)", ScriptMethodPointer(moveToGameObjectDelegate));
Voila!