I've added support for anonymous functions in the latest revision (2202) of the AngelScript WIP.
The syntax for using anonymous functions look like this:
void main()
{
// Passing an anonymous function to a function expecting a function pointer
DoSomethingWithACallback(function(a,b) {return a+b});
// Store a pointer to an anonymous function for later use
callback @cb = function(a,b) {return a*b;}
}
// The anonymous function will take on the signature that is expected by the target
funcdef int callback(int, int);
int DoSomethingACallback(callback @cb)
{
return cb(1, 2);
}
Let me know your thoughts, and if you find any problem with this new feature please let me know so I can have it fixed before I make the official release.
Observe, the anonymous functions cannot be used as closures yet. That will have to wait for future time (if ever) as it would require a lot more changes in the compiler.
Regards,
Andreas