I am currently working on a legacy codebase that was using AngelScript 2.4.1e for its scripting engine and I'm trying to upgrade it.
After having settled with the compilation errors, one problem that I encountered is that all the scripts have a common function which is called from the application to set an instance of a Game class and that Game class is an interface/wrapper for interacting with the game engine (each script instance is sandboxed).
Scripts:
Game@ instance;
void SetInstance(Game &in i)
{
@instance = @i;
}
Application:
class Game
{
private :
Game();
public :
Game(IScript *);
virtual ~Game();
int AddRef();
int Release();
void ScriptLoaded();
// ...
};
// Legacy code:
r=engine->RegisterObjectType("Game", sizeof(Game), asOBJ_CLASS);
r=engine->RegisterObjectBehaviour("Game", asBEHAVE_ADDREF, "void f()", asMETHOD(Game, AddRef), asCALL_THISCALL);
r=engine->RegisterObjectBehaviour("Game", asBEHAVE_RELEASE, "void f()", asMETHOD(Game, Release), asCALL_THISCALL);
// ...
// After upgrade:
r=engine->RegisterObjectType("Game", sizeof(Game), asOBJ_REF); assert(r >= 0);
r=engine->RegisterObjectBehaviour("Game", asBEHAVE_ADDREF, "void f()", asMETHOD(Game, AddRef), asCALL_THISCALL); assert(r >= 0);
r=engine->RegisterObjectBehaviour("Game", asBEHAVE_RELEASE, "void f()", asMETHOD(Game, Release), asCALL_THISCALL); assert(r >= 0);
// ...
// In Game's ScriptLoaded method
context->Prepare(module->GetFunctionByName("SetInstance"));
context->SetArgObject(0, (void*)this);
context->Execute();
The error that I am getting and being thrown during runtime is "Parameter type can't be 'Game&in', because the type cannot be instantiated." when SetInstance is being compiled/called.
How can I fix it? I tried registering a copy constructor with asBEHAVE_FACTORY but no luck. Keeping in mind I would like to avoid editing manually over 300 scripts if possible.
Thanks in advance.