Advertisement

Interfaces and base classes

Started by July 26, 2013 03:19 PM
2 comments, last by SiCrane 11 years, 4 months ago

I'm trying to register a component system with AngelScript for my engine right now I have a C++ component that wraps an AngelScript object. It basically just calls the matching methods on the AngelScript object whenever the function is called in C++, so when the C++ update() method gets called the AngelScript object instance's update() method is called as well. What I want is for all the components to derive from a base component class that contains a reference to the owner game object. On the C++ side i have an IComponent interface. If I register the IComponent interface as a reference type is there any way to register my C++ IComponent implementations as being derived from the AngelScript component base class?

No, a C++ class cannot derive from a script class, neither can a script class derive from a C++ class.

You can however provide a shared AngelScript component base class that implements the desired binding mechanism to tie the script class to the C++ class. This shared class can then be derived by all the custom components.

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

Advertisement

So you can't register class heirarchies at all?

Yes and no. There's no explicit method in the registration interface to specify that two classes are specifically related by inheritance. However, you can register implicit and explicit cast behaviors. You can register an implicit cast from derived to base and an explicit cast from base to derived and that usually takes care of all your needs for the relation between base and derived classes. See the manual on class hierarchy.

This topic is closed to new replies.

Advertisement