Advertisement

Inheritance From Internal C++ Classes

Started by July 17, 2016 11:34 PM
2 comments, last by Solokiller 8 years, 4 months ago

Say:

//c++


class a 
{
a *def;
};
class c : a
{
 int abc;
};


//as
class b : c
{
   b() 
  {
     @a;
  }
}

I Tried something like this but kept running into an error where angel script was not properly set up, then it crashed angel script.

What is the proper way to inherit from a c++ class, what flags do I have to set to get it to work correctly?

chasester

Extending classes can't be done using built-in means. You'll have to write some code to make it work.

I've put together a utility library last week that takes care of most of it, it's on Github: https://github.com/SamVanheer/AngelscriptUtils

The code you want is the extension support, which is defined primarily in 3 files:

https://github.com/SamVanheer/AngelscriptUtils/blob/9c024dfcf80ff280cd96f4ffa714de0efb291e0e/src/Angelscript/util/CASExtendAdapter.h

https://github.com/SamVanheer/AngelscriptUtils/blob/9c024dfcf80ff280cd96f4ffa714de0efb291e0e/src/Angelscript/util/ASExtendAdapter.h

https://github.com/SamVanheer/AngelscriptUtils/blob/9c024dfcf80ff280cd96f4ffa714de0efb291e0e/src/Angelscript/util/ASExtendAdapter.cpp

CASExtendAdapter is a template class that is inherited from to implement the adapter between the C++ and script class.

The other files define helper functions to define script code that scripts can inherit from to extend from the classes.

For an example of its use, see these classes:

https://github.com/SamVanheer/AngelscriptUtils/blob/9c024dfcf80ff280cd96f4ffa714de0efb291e0e/src/test/CBaseEntity.h

https://github.com/SamVanheer/AngelscriptUtils/blob/9c024dfcf80ff280cd96f4ffa714de0efb291e0e/src/test/CScriptBaseEntity.h

https://github.com/SamVanheer/AngelscriptUtils/blob/9c024dfcf80ff280cd96f4ffa714de0efb291e0e/src/test/ASCBaseEntity.h

The typedefs are critical for the macros to work. Otherwise you'll have to write a lot more code to handle each call separately.

The script API is just as important as the C++ code:

https://github.com/SamVanheer/AngelscriptUtils/blob/9c024dfcf80ff280cd96f4ffa714de0efb291e0e/src/test/Main.cpp#L112

https://github.com/SamVanheer/AngelscriptUtils/blob/9c024dfcf80ff280cd96f4ffa714de0efb291e0e/src/test/Main.cpp#L184

Registering the C++ class API, the base class method call type and the interface you can use to take handles to script extensions is an important part.

Creating the instance is handled like this:

https://github.com/SamVanheer/AngelscriptUtils/blob/master/src/test/Main.cpp#L337

The library is a WIP, but this should let you get started with your own code.

Based on your script code and what you said about it not being set up correctly, you're still having problems with getting Angelscript integration done. I suggest getting that set up before trying to integrate class extension support.

Advertisement

@Solokiller: Thanks for sharing this. I'll have to take a look at what you've done myself. Perhaps I'll include some of this as helper add-ons (with your permission of course).

@chasester123: The manual has an article 'Inheriting from application registered classes'. Hopefully it should allow you to get your implementation working.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

No problem, glad to help. You can add them if you want.

This topic is closed to new replies.

Advertisement