AngelScript
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Registering object methods

Class methods are registered with the RegisterObjectMethod call. Both non-virtual and virtual methods are registered the same way.

Static class methods are in reality global functions so those should be registered as global functions and not as object methods.

// 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 );
See Also
Registering a function for more details on how the macros work.