It is posisble to inherit in chaiscript?


#1

Hello, I’m just starting to try scripts in general. I saw that in Unity3D you have to inherit from MonoBehaviour inside the script. So this should provide basic functions inherited. Is this possible in chaiscript? For example:

Define this class inside C++ or in another script

class ScriptInterfaceExample
{
public:
virtual void update(float dt) { };

}

And then use that class as a base in the script:

class EnemyMovement : public ScriptInterfaceExample
{
public:
void update(float dt) {
//Do something here…
}

}

Thank you and sorry if I’m asking something stupid, just starting in scripts world.


#2

No, not directly. There is a technique for doing inheritance if that’s really what you want: https://github.com/ChaiScript/ChaiScript/blob/develop/samples/inheritance.cpp

But you probably don’t actually want / need to do that in ChaiScript. ChaiScript supports easy and natural (and well performing) sharing of functions between script and C++. Creating a call-back function and registering it is probably what you want to do.

See here: Best practice for passing/processing events for a discussion about that.


#3

Thank you, I think that you are right about the call-backs funcs! :smile:

I will try to rethink it to use that.