Hi,
please find attached a patch to support function call operators in angelscript (the patch applies to the 2.28.0 official release). The initial topic discussing this project can be found here: http://www.gamedev.net/topic/652292-function-call-operators/
Due to my limited experience with Angelscript, you may want to do things differently, but I have tried to reuse existing code as much as possible to avoid duplication of the existing logic. Also, the impact should be pretty small on other features.
Here is an example of definition and usage:
// declaration example
class FuncCallClass
{
void opCall(){}
void opCall(int i){return 0}
};
// usage example
void main(void)
{
FuncCallClass func;
func();
int j=func(10);
}
So far, the following cases have been tested, on both Windows and Mac, with or without JIT:
- direct call for global or local variables
- calling this() inside a class method
- calling the operator on a class handle
- calling the operator on a class member variable
- calling the operator on a class member thru a property accessor
- calling the operator on an object in an array (array<Functor> a={f}; a[0]();)
- calling the operator with or without arguments and return values.
I hope you will find it useful. I do not have test cases for the angelscript tests suite right now, as I am having issues building the tests on Mac (I managed to do it but it requires a couple of changes, so the diff would be a mess!).