Jump to content
  • Advertisement
Robotex

Upgrading legacy code

Recommended Posts

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.

 

Edited by Robotex

Share this post


Link to post
Share on other sites
Advertisement

You're registering Game only as asOBJ_REF, which means you can only pass it as Game@ and &inout. You're passing it with &in, which I believe is only possible if it's an asOBJ_VALUE.

Your choices are to change the script to simply pass the Game param as "Game &i" (or "Game@ i") rather than "Game &in i", or to allow the class to be a value as well, which might be more involved. You can take a look at the scripthandle addon for an example, which is a combination of asOBJ_VALUE, asOBJ_ASHANDLE, and asOBJ_GC.

Changing the scripts is the best solution, in my opinion. (Search & replace all files maybe?)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!