Sign in to follow this  
DaesDemon

Transtypage Question

Recommended Posts

Hi to all, I would like to know a way to executing scriptstring in script: My problem is: I have different C++ object that i would like to use the same Script interface: getValue() setValue(xxx)
C++

class Variant
{
std::string type;
enum
{
    bool mb;
    int mi;
}
    Control(bool b) {mb = b);
    Control(int i) {mi = i);
    // operator de transtypage
    operator bool() const {return mb};
    operator int() const {return mi};
}

class IControl
{
    Variant getValue()=0;
    setValue(Variant v)=0;
}

class BoolControl:IControl
{
    bool mb;
    Variant getValue() {return Variant(mb); }
    setValue(Variant v) { mb = v.mb; }
}

class IntControl:IControl
{
    int mi;
    Variant getValue() {return Variant(mi); }
    setValue(Variant v) { mi = v.mi; }
}




If i declare the Control and Variant Class in AngelScript, is it possible to do something like this?
C++
Engine->RegisterGlobalProperty("Control control",aBoolControlPtr;assert( r >= 0 );


AngelScript

void doSomethingWithABool(bool b)
{
   if (b) ....
   else ....
}

doSomethingWithABool(control.getValue())




In two word , can i declare only the interface of IControl in AngelScript ? And will the transypage operator be used by angelScript ? Thanks for informations and sorry for the little specific domain ;) [Edited by - DaesDemon on September 2, 2005 5:13:02 AM]

Share this post


Link to post
Share on other sites
AngelScript does not yet support the ability to register cast operators for types. So AngelScript will not be able to implicitly convert the variant type to a boolean value.

I have plans on implementing this in a future version, but currently you will have to register either a function or a method that does the conversion. The script would then have to call this function explicitly. Example:


doSomethingWithABool(cbool(control.getValue()));


The rest should work just fine, as AngelScript supports virtual method pointers.

Regards,
Andreas

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this