Angelscript addon Template Containers  2.31.0
STL container powerr for Angelscript
Registering hash functions

Unordered containers require your classes to have a hash function registered.

A C++ class requires a hash function registered on the c++ side and the angelscript side.

An Angelscript class requires a hash function as a method of the class.

Registering a hash function for a c++ class:

#include "aatc_hash.hpp"
class MyCppClass{
int something;
};
/*
Specialize the aatc hashfunctor, to let the c++ side of aatc to know about your class.
With this your c++ class can be used with tempspec'd versions of unordered containers.
*/
namespace aatc {
namespace hash {
template<> class hashfunctor<MyCppClass> {
public:
config::t::hash operator()(const MyCppClass& a) const{
return a.something * 12345;
}
};
};//namespace hash
};//namespace aatc
/*
Tell Angelscript that this c++ class does indeed have a hashing function available.
With this and the specializaton above, your c++ class can be used with templated or tempspec'd versions of unordered containers.
*/
aatc::hash::Register(engine,"MyCppClass_name_in_script");

Registering a hash function for an Angelscript class:

class Material{
int id;
aatc_hash_t hash(){
return id * 12345;
}
}

The return type of the Angelscript method and its name are both required to be exact for AATC to find them.

Both of the names can be set in the config:

  • The return typedef name can be set in aatc::config::scriptname::t::hash
  • The return type itself can be set in aatc::config::scriptname::t::hash_actual
  • The method name can be set in aatc::config::scriptname::method::content::hash