• Advertisement
Sign in to follow this  

AngelScript WIP - anonymous functions

This topic is 1002 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

 

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement