Jump to content
  • Advertisement
Sign in to follow this  
chasester123

Inheritance From Internal C++ Classes

This topic is 733 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

@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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!