It appears to be complaining about the actual class itself, but I do not know why. Is there anyone out there who can point me in the right direction? If you need more information let me know.
Ah ok, I was hoping the native implementation would work. It seems to be complaining about the fact that it is a template function. I will see if I can expose it as a template to AngelScript, then try the generic implementation as you suggested. Thank you, I will respond with what I find!
[admin edit] the code seems to make problems with the code highlighting. I've disabled bbcodes to at least see the code. Maybe move it over to some source hoster.[/admin edit]
yeah thx...
if you need the vector3d in angelschript here we go:
// Register the type
r = engine->RegisterObjectType(name.c_str(), sizeof(core::vector3d<T>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK); assert( r >= 0 );
// Register the object properties
r = engine->RegisterObjectProperty(name.c_str(), (type + " X").c_str(), offsetof(core::vector3d<T>, X)); assert( r >= 0 );
r = engine->RegisterObjectProperty(name.c_str(), (type + " Y").c_str(), offsetof(core::vector3d<T>, Y)); assert( r >= 0 );
r = engine->RegisterObjectProperty(name.c_str(), (type + " Z").c_str(), offsetof(core::vector3d<T>, Z)); assert( r >= 0 );
// Register the constructors
r = engine->RegisterObjectBehaviour(name.c_str(), asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(Vector3dDefaultConstructor<T>), asCALL_CDECL_OBJLAST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour(name.c_str(), asBEHAVE_CONSTRUCT, "void f(const vector3df &in)", asFUNCTION(Vector3dCopyConstructor<T>), asCALL_CDECL_OBJLAST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour(name.c_str(), asBEHAVE_CONSTRUCT, ("void f(" + type +", "+ type +", "+ type + ")").c_str(), asFUNCTION(Vector3dInitConstructor<T>), asCALL_CDECL_OBJLAST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour(name.c_str(), asBEHAVE_CONSTRUCT, ("void f(" + type + ")").c_str(), asFUNCTION(Vector3dInit2Constructor<T>), asCALL_CDECL_OBJLAST); assert( r >= 0 );
// Register the operator overloads
r = engine->RegisterObjectMethod(name.c_str(), "vector3df &opAddAssign(const vector3df &in)", asMETHODPR(core::vector3d<T>, operator+=, (const core::vector3d<T>&), core::vector3d<T>&), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "vector3df &opSubAssign(const vector3df &in)", asMETHODPR(core::vector3d<T>, operator-=, (const core::vector3d<T>&), core::vector3d<T>&), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), ("vector3df &opMulAssign(" + type + ")").c_str(), asMETHODPR(core::vector3d<T>, operator*=, (T), core::vector3d<T>&), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), ("vector3df &opDivAssign(" + type + ")").c_str(), asMETHODPR(core::vector3d<T>, operator/=, (T), core::vector3d<T>&), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "bool opEquals(const vector3df &in) const", asMETHODPR(core::vector3d<T>, operator==, (const core::vector3d<T>&) const, bool), asCALL_THISCALL); assert(r >= 0);
r = engine->RegisterObjectMethod(name.c_str(), "vector3df opAdd(const vector3df &in) const", asMETHODPR(core::vector3d<T>, operator+, (const core::vector3d<T>&) const, core::vector3d<T>), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "vector3df opSub(const vector3df &in) const", asMETHODPR(core::vector3d<T>, operator-, (const core::vector3d<T>&) const, core::vector3d<T>), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), ("vector3df opMul(" + type + ") const").c_str(), asMETHODPR(core::vector3d<T>, operator*, (T) const, core::vector3d<T>), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), ("vector3df opDiv(" + type + ") const").c_str(), asMETHODPR(core::vector3d<T>, operator/, (T) const, core::vector3d<T>), asCALL_THISCALL); assert( r >= 0 );
// Register the object methods
r = engine->RegisterObjectMethod(name.c_str(), (type + " getLength() const").c_str(), asMETHOD(core::vector3d<T>, getLength), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), (type + " getLengthSQ() const").c_str(), asMETHOD(core::vector3d<T>, getLengthSQ), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), (type + " dotProduct(const vector3df &in) const").c_str(), asMETHOD(core::vector3d<T>, dotProduct), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), (type + " getDistanceFrom(const vector3df &in) const").c_str(), asMETHOD(core::vector3d<T>, getDistanceFrom), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), (type + " getDistanceFromSQ(const vector3df &in) const").c_str(), asMETHOD(core::vector3d<T>, getDistanceFromSQ), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "vector3df crossProduct(const vector3df &in) const", asMETHOD(core::vector3d<T>, crossProduct), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "bool isBetweenPoints(const vector3df begin, const vector3df end) const", asMETHOD(core::vector3d<T>, isBetweenPoints), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "vector3df& normalize()", asMETHOD(core::vector3d<T>, normalize), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "string toString()", asFUNCTION(toString<T>), asCALL_GENERIC); assert( r >= 0 );
}
template<typename T>
void static Vector3d_Generic(asIScriptEngine *engine, std::string name)
{
s32 r = 0;
std::string type = typeid(T).name();
// Register the type
r = engine->RegisterObjectType(name.c_str(), sizeof(core::vector3d<T>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK); assert( r >= 0 );
// Register the object properties
r = engine->RegisterObjectProperty(name.c_str(), (type + "x").c_str(), offsetof(core::vector3d<T>, X)); assert( r >= 0 );
r = engine->RegisterObjectProperty(name.c_str(), (type + "y").c_str(), offsetof(core::vector3d<T>, Y)); assert( r >= 0 );
r = engine->RegisterObjectProperty(name.c_str(), (type + "z").c_str(), offsetof(core::vector3d<T>, Z)); assert( r >= 0 );
// Register the constructors
r = engine->RegisterObjectBehaviour(name.c_str(), asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(Vector3dDefaultConstructor_Generic<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour(name.c_str(), asBEHAVE_CONSTRUCT, "void f(const vector3df &in)", asFUNCTION(Vector3dCopyConstructor_Generic<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour(name.c_str(), asBEHAVE_CONSTRUCT, ("void f(" + type +", "+ type +", "+ type + ")").c_str(), asFUNCTION(Vector3dInitConstructor_Generic<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour(name.c_str(), asBEHAVE_CONSTRUCT, ("void f(" + type +")").c_str(), asFUNCTION(Vector3dInit2Constructor_Generic<T>), asCALL_GENERIC); assert( r >= 0 );
// Register the operator overloads
r = engine->RegisterObjectMethod(name.c_str(), "vector3df &opAddAssign(const vector3df &in)", asFUNCTION(Vector3dAddAssign_Generic<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "vector3df &opSubAssign(const vector3df &in)", asFUNCTION(Vector3dSubAssign_Generic<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), ("vector3df &opMulAssign(" + type +")").c_str(), asFUNCTION(Vector3dMulAssign_Generic<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), ("vector3df &opDivAssign(" + type +")").c_str(), asFUNCTION(Vector3dDivAssign_Generic<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "bool &opEquals(const vector3df &in)", asFUNCTION(vector3dfEqualGeneric<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "bool opEquals(const vector3df &in) const", asFUNCTION(vector3dfEqualGeneric<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "vector3df opAdd(const vector3df &in) const", asFUNCTION(Vector3dAdd_Generic<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "vector3df opSub(const vector3df &in) const", asFUNCTION(Vector3dSub_Generic<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), ("vector3df opMul(" + type +") const").c_str(), asFUNCTION(Vector3dMulFloat_Generic<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), ("vector3df opDiv(" + type +") const").c_str(), asFUNCTION(Vector3dDivFloat_Generic<T>), asCALL_GENERIC); assert( r >= 0 );
// Register the object methods
r = engine->RegisterObjectMethod(name.c_str(), (type +" getLength() const").c_str(), asFUNCTION(getLength<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), (type +" getLengthSQ() const").c_str(), asFUNCTION(getLengthSQ<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), (type +" dotProduct(const vector3df &in) const").c_str(), asFUNCTION(dotProduct<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), (type +" getDistanceFrom(const vector3df &in) const").c_str(), asFUNCTION(getDistanceFrom<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), (type +" getDistanceFromSQ(const vector3df &in) const").c_str(), asFUNCTION(getDistanceFromSQ<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "vector3df crossProduct(const vector3df &in) const", asFUNCTION(crossProduct<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "bool isBetweenPoints(const vector3df begin, const vector3df end) const", asFUNCTION(isBetweenPoints<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "vector3df& normalize()", asFUNCTION(normalize<T>), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod(name.c_str(), "string toString()", asFUNCTION(toString<T>), asCALL_GENERIC); assert( r >= 0 );
}