Jump to content
  • Advertisement
Sign in to follow this  
VoidSpirit

opCast and opConv differences

This topic is 682 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

Hello!

 

What are differences between opCast and opConv operations? How they are differs internally? On which data types I must use

cast<type> operation, and when - type(...) ? Can I safely use both operations in all case or an application's crash may occurs?

 

At last - what operation I must use for getting values from DictionaryValue for different storing types?

 

Thanks for answers

Share this post


Link to post
Share on other sites
Advertisement

opCast is used for polymorphism, i.e. when an object can be represented through different interfaces and you wish to cast between the interfaces while still referring to the same object.

 

opConv is used to convert values. This is used when you don't need to keep a reference to the original object.

 

You shouldn't get any application crashes with either. 

 

The manual explains how to use the dictionary

 

int val = int(dict['value']);      // this uses the opConv operator
@handle = cast<obj>(dict['handle']);  // this uses the opCast operator

Share this post


Link to post
Share on other sites

I look at CScriptDictValue code and see both opCast and opConv operations reference to CScriptDictValue_opCast writing a value to prepared stack place. 

In your example:

- casting to int - by opConv

- casting to obj - by opCast

can I write:

int val=cast<int>(dict['value']);

@handle = obj(dict['handle']);

or not and why? What does determine choice between opConv and opCast?

Share this post


Link to post
Share on other sites

int val=cast<int>(dict['value']);

 

This isn't allowed, because the int type doesn't support handles, i.e. it cannot be referred to through a handle.

 

@handle = obj(dict['handle']);

 

This is allowed (if the obj type has the appropriate constructor). It would make a copy of the object in dict['handle'] and handle would refer to the copy rather than the object referred to by dict['handle'].

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!