Angelscript addon Template Containers  2.31.0
STL container powerr for Angelscript
Registering tempspecs

Before you can register a template specialization for a container, you must first register the content class itself.

You can only register template specializations for these containers:

  • vector
  • list
  • deque
  • set
  • unordered_set

map and unordered_map are not available because they take 2 template parameters and that would require partial template specialization which angelscript probably doesnt support.


The containers require certain operators to be implemented before they can be specialized:

  • vector
    • operator equals
    • operator less
  • list
    • operator equals
    • operator less
  • deque
    • operator equals
    • operator less
  • set
    • operator less
  • unordered_set
    • operator equals
    • pseudo-operator hash

Hash is not an operator, but a functor by name of aatc::hash::hashfunctor

See: Registering hash functions for all your hashing needs


The tempspec registration functions work like this:

#include "aatc_container_vector.hpp"
aatc::container::tempspec::vector<MyCppClass>::Register(engine, "MyCppClass_name_in_script");


Warning: You should not register MyCppClass* as a tempspec. If you want to store handles, you should use a templated container instead.


Examples

Registering a template specialization of the class "myVec3" for the containers vector and list:

//include the container headers that you will be needing
#include "aatc_container_vector.hpp"
#include "aatc_container_list.hpp"
class myVec3{
public:
float x,y,z;
myVec3(float x,float y,float z);
bool operator==(const myVec3& other);
int angelscript_opCmp(const myVec3& other);
};
void your_aatc_tempspec_registration(asIScriptEngine* engine){
aatc::RegisterAllContainers(engine);
engine->RegisterObjectType("myVec3", ...);
engine->RegisterObjectMethod("myVec3", "bool opEquals(const myVec3 &in)", asMETHOD(myVec3,operator==),asCALL_THISCALL);
engine->RegisterObjectMethod("myVec3", "int opCmp(const myVec3 &in)", asMETHOD(myVec3,angelscript_opCmp),asCALL_THISCALL);
}