I have a use case for a generic funcdef where all functions should be accepted for the parameter.
This is the code that requires it:
Basically i have a scheduler class that can execute a function at a later point in time. The caller passes in a function handle to do this. Right now that function handle parameter is a ?& in parameter type, but this means there is no compile time checking going on, and object methods can only be passed in by creating a funcdef and converting the method to that.
I propose adding a new parameter type similar to ?& in that allows an application function to take any function or object method as though the parameter type were a compatible funcdef:
funcdef@ parameterName
Used in a function or method declaration like this:
void MyFunction(funcdef@ myFunctionParameter)
The C++ function would simply take an asIScriptFunction pointer:
void MyCPPFunction(asIScriptFunction* myFunctionParameter)
{
//Use it, call Release when done
}
Generic calls would work the same way as they do now (i assume my code is wrong because i'm using GetArgAddress instead of GetArgObject, but it still works).
Script calls would handle it like this:
bool ACompareFunction(SomeClass@ lhs, SomeClass@ rhs) {…}
class Foo
{
void SomeOtherMethod(const string& in text) {…}
}
MyFunction(ACompareFunction); //Implicit conversion to funcdef
Foo foo;
MyFunction(funcdef(foo.SomeOtherMethod)); //Explicit conversion to the any funcdef type
This would eliminate the need to perform runtime type checking and makes it easier for script authors to see if their code will compile or not.
It should also be possible for any existing funcdef to implicitly convert to the any funcdef type.