Advertisement

opCast and opConv differences

Started by September 03, 2016 06:00 PM
3 comments, last by VoidSpirit 8 years, 2 months ago

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

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

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

Advertisement

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?

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'].

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!

I'll continue my studies and I think it was not last question...

This topic is closed to new replies.

Advertisement