I have an interface defined in C++:
class IFoo
{
public:
virtual void FooMethod();
};
I have registered the interface in AngelScript engine:
ASEngine->RegisterInterface("IFoo");
ASEngine->RegisterInterfaceMethod("IFoo", "void FooMethod()");
I have a script (foo.fos) with implementation of this interface:
class FooImpl : IFoo
{
void FooMethod() {/*doing something totally useful*/}
}
I have also registered Global function which I am calling from my script with new instance of my FooImpl class as parameter:
ASEngine->RegisterGlobalFunction("void RetrieveFoo(IFoo& foo)", asFUNCTION(RetrieveFoo), asCALL_CDECL);
And I have my RetrieveFoo function in C++ code:
void RetrieveFoo(asIScriptObject* obj)
{
if(obj == NULL)
{
Log("No object has been passed");
return;
}
//I want to do something with passed FooImpl
}
My question is:
Is it possible to cast asIScriptObject* obj to IFoo interface and directly call FooMethod() or I have to do it the "ugly" way, which makes the interface useless (creating context, getting function to call, setting parameters, and executing it)?