🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

AngelScript WIP - anonymous functions

Started by
-1 comments, last by WitchLord 8 years, 11 months ago

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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement