Type behaviours

Todo:
Complete this page with more examples

Math operators

All of these, with exception to asBEHAVE_NEGATE, should be registered with two parameters using asIScriptEngine::RegisterGlobalBehaviour. asBEHAVE_NEGATE should be registered with no parameters using asIScriptEngine::RegisterObjectBehaviour.

Comparison operators

These should be registered with two parameters using asIScriptEngine::RegisterGlobalBehaviour. All of them should return a bool type.

Bitwise operators

These should be registered with two parameters using asIScriptEngine::RegisterGlobalBehaviour.

Assignment operators

All of these should be registered with one parameter using asIScriptEngine::RegisterObjectBehaviour. Preferably the functions should return a reference to the object itself.

Index operator

This behaviour should be registered with one parameter using asIScriptEngine::RegisterObjectBehaviour.

Cast operators

asBEHAVE_VALUE_CAST must be registered without parameters using asIScriptEngine::RegisterObjectBehaviour. The return type can be any type, except bool and void.

asBEHAVE_REF_CAST must be registered with one parameter using asIScriptEngine::RegisterGlobalBehaviour. The parameter must be an object handle, as must the return type.

// Example REF_CAST behaviour
B* castAtoB(A* a)
{
    B* b = dynamic_cast<B*>(a);
    if( b == 0 )
    {
        // Since the cast couldn't be made, we need to release the handle we received
        a->release();
    }
    return b;
}

// Example registration of the behaviour
r = engine->RegisterGlobalBehaviour(asBEHAVE_REF_CAST, "B@ f(A@)", asFUNCTION(castAToB), asCALL_CDECL); assert( r >= 0 );

See also:
asBEHAVE_CONSTRUCT and asBEHAVE_FACTORY in Memory management as well for an alternative value cast operator.

Memory management

These must be registered using asIScriptEngine::RegisterObjectBehaviour. asBEHAVE_CONSTRUCT and asBEHAVE_FACTORY may take parameters for object initialization, but the others shouldn't use parameters.

See also:
Registering an object type for more information on how to register types.

Garbage collection

These behaviours are exclusive for objects that have been registered with the flag asOBJ_GC. All of them should be registered using asIScriptEngine::RegisterObjectBehaviour.

See also:
Implementing a garbage collected object for more information on using these.

Generated on Sun Jun 8 11:21:43 2008 for AngelScript by  doxygen 1.5.5