🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Transtypage Question

Started by
1 comment, last by DaesDemon 18 years, 10 months ago
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]
Advertisement
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

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

Thank you very much witchlord, for your quick and precise informations and help:)

Regards,
DaesDemon

This topic is closed to new replies.

Advertisement