Class Binding Utility

Started by
0 comments, last by WitchLord 18 years, 6 months ago
If you find yourself binding a lot of classes that all have the basic operators, you might find this little template usefull. Instead of writing lots of wrapper functions, just grab them out of the template! Instead of
asFUNCTION(SomeWrapperYouHadToWrite)
use
asFUNCTION(CDA<Type>::Construct)
. The wrapper is generated for you. Use with the calling convention asCALL_CDECL_OBJLAST.

#ifndef JM_SERVER_BIND_CLASS_UTIL_H
#define JM_SERVER_BIND_CLASS_UTIL_H

template <typename T>
class CDA
{
public:
	static void Construct(T* ptr) { new (ptr) T(); }
	static void CopyConstruct(const T& rhs, T* ptr) { new (ptr) T(rhs); }
	static void Destroy(T* ptr) { ptr->~T(); }
	static T& Assign(const T& rhs, T* ptr) { return (*ptr) = rhs; }
};

#endif

I plan on expanding this to cover wrappers for all binary operators (And probably the unary operators too, just for consistency) before releasing it as part of my AutoBind utility I am working on. By then, it will be changed so that the template will still compile if your class does not support a certain operator. Just don't try and bind that operator. [PS - Witchlord; does 2.x support the pre/post increment/decrement operators?]
Advertisement
No, AngelScript currently doesn't support overloading the increment and decrement operators, it's on my to-do list though.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement