I've been scratching my head over this one for a few days, thought you guys might have a better idea.
Essentially I want to define a standard interface that can be then inherited from in Angelscript classes. For example, say I have a card game like Magic The Gathering, my base class might look like:
class Card
{
public:
virtual void PreDrawPhase() = 0;
virtual void PostDrawPhase() = 0;
// etc....
};
Then I want to be able to define new cards and their respective behavior in Angelscript, while being able to handle them in C++ (by handling the interface). How can I achieve this?
Disclaimer: I have never used Angelscript in any "real" Project which is why the following answer should be taken with a grain of salt. It worked in the small test code i set up for it and most code snippets were explained in some detail in the official manual, but this is absolutly no guarantee whatsoever that it is a sound design and can be employed reasonably in your game.
The relevant parts to accomplish your goal are, I believe, described pretty well in the official manual:
This describes how to define and use an Interface.
This describes how to instantiate and use "Script Classes" from within C++.
Using this information, we could potentially write a simplistic wrapper class, that on construction, creates an instance of a certain class and releases it on destruction, whilst providing member functions that call the respective members of the script class:
(Note: For the sake of brevity, I omitted all error handling and some other important practices, like the Rule of Tree(The class below cannot be copied without breaking a lot...))
Header:
Implementation:
I believe the code is pretty self explanatory(correct me if i am wrong and i will try to elaborate), therefore I will just describe the basic idea:
As mentioned in the beginning, i am everything but experienced regarding Angelscript, so this may indeed be a very suboptimal method and it is quite propable better solutions do exist.