Jump to content
  • Advertisement
Sign in to follow this  
DaesDemon

Transtypage Question

This topic is 4824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!