I have an object class that can host a variety of component subclasses. A helper function in object is components_of_type<T>, which returns an array of components of the specified type hosted by the object. Is there a way to register that functionality with a similar syntax in AngelScript? Right now I can do wrappers for specializations and expose them as "x_components()" or "y_components()" to wrap components_of_type<x> and components_of_type<y> separately, but a near-unified syntax between C++ and AngelScript code would be a plus.
Registering a C++ template function,
Moderators - Reputation: 4365
Posted 18 July 2013 - 02:26 PM
It's currently not possible to register functions with the syntax 'components_of_type<T>' in AngelScript.
In C++ the template function is instanciated at compile time for each type used by the code. But for AngelScript to have the same syntax for a registered function you would have to somehow have a unified implementation that is able to work with all types and dynamically deciding at runtime what to do for each type.
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game