AngelScript
|
Class methods are registered with the RegisterObjectMethod call.
// Register a class method void MyClass::ClassMethod() { // Do something } r = engine->RegisterObjectMethod("mytype", "void ClassMethod()", asMETHOD(MyClass,ClassMethod), asCALL_THISCALL); assert( r >= 0 );
It is also possible to register a global function that takes a pointer to the object as a class method. This can be used to extend the functionality of a class when accessed via AngelScript, without actually changing the C++ implementation of the class.
// Register a global function as an object method void MyClass_MethodWrapper(MyClass *obj) { // Access the object obj->DoSomething(); } r = engine->RegisterObjectMethod("mytype", "void MethodWrapper()", asFUNCTION(MyClass_MethodWrapper), asCALL_CDECL_OBJLAST); assert( r >= 0 );