Advertisement

Interfaces

Started by November 02, 2010 12:10 PM
3 comments, last by _orm_ 14 years, 1 month ago
Angelscript documentation explains how to declare an interface for the script, but how can I call a script object from C++ that actually implemented the interface ?

I didn't find neither documentation nor samples. Thanks!

- Federico
You call an interface method just like you would call any other method: from the asIScriptObject pointer you can use GetObjectType() to get an asIObjectType pointer. From the asIObjectType object you can GetMethodIdByDecl() to get an id for the object method you want to call. You can use that id with as an argument to asIScriptContext::Prepare(). Don't forget to call asIScriptContext::SetObject() as well.
Advertisement
Thanks! now its working fine!

Maybe someone should create a wiki or something to start extending the documentation.

And I was wondering, is there a way to extend C++ classes within the script? Something like UnrealScript ?

For example:

// C++
class Weapon
{
virtual void Update() {}
virtual int GetType() { return 0; }
}

// Script
class Pistol : Weapon
{
void Update() { /* */ }
int GetType() { return 1; }
}

If I can do something like that without hacks or complicated error-prone code, I think AngelScript will be my scripting engine : )

- Enlight
There is already a wiki for AngelScript.

Currently there is no built in way to extend C++ classes with script classes though it is possible to fake it.
Am I the only one here getting a sense of dejavu? :p
From pereonal experience, the easiest way to inherit from registered classes is to write a proxy class in angelscript. You could even go so far as to compile the class as a string in the application if you want transparency.

This topic is closed to new replies.

Advertisement