12.5. Dynamic RTTI type casts
The DYNAMIC_CAST_RTTI module implements runtime dynamic casting between class
types using RTTI information. It provides safe downcasting with null results
on type mismatch, similar to C++ dynamic_cast.
All functions and symbols are in “dynamic_cast_rtti” module, use require to get access to it.
require daslib/dynamic_cast_rtti
12.5.1. Variant macros
- dynamic_cast_rtti.ClassAsIs
Variant macro that implements class dynamic casting via is and as.
12.5.2. Dynamic casts
- dynamic_cast_rtti.dynamic_type_cast(instance: auto; otherclass: auto(TT)): TT?
Casts a class instance to the target type using RTTI, returns null if the cast fails.
- Arguments:
instance : auto
otherclass : auto(TT)
- dynamic_cast_rtti.force_dynamic_type_cast(instance: auto; otherclass: auto(TT)): TT?
Casts a class instance to the target type using RTTI, panics if the cast fails.
- Arguments:
instance : auto
otherclass : auto(TT)
- dynamic_cast_rtti.is_instance_of(instance: auto(TCLS)?; otherclass: auto(TT)): auto
Returns true if the class instance is an instance of the specified class using RTTI.
- Arguments:
instance : auto(TCLS)?
otherclass : auto(TT)