Function as argument
Monkey Forums/Monkey Programming/Function as argument
| ||
| Hey ! Is it possible to use a function as a parameter for methods or functions? Example: Function Test(a:Function) a.Call(); End It's possible in js and as3. Thanks so far! |
| ||
| No |
| ||
| So hopefully mark will implement it. I think it's an important thing |
| ||
| So hopefully mark will implement it I doubt it, Mark wrote about function pointers awhile back: ...and some stuff removed, such as pointers. Yes, POINTERS! Function pointers too! http://marksibly.blogspot.com/2010/07/update.html |
| ||
| That was not a good idea to remove them.... What's the reason for removing that feature? |
| ||
| The reason is simple. It doesn't work on all targets. Java has no pointers at all. You have to use interfaces to use some kind of function pointers. Something like: Class ICallBack Abstract Method call:Void() Abstract End Class Then you have your other class where you want to use this call method:
'Implementation of the interface
Class MyCallBack Extends ICallBack
Method call:Void()
'Do something fancy here!
End Method
End Class
'Your function using the "function pointer"
Function Test( a:ICallBack )
a.call();
End Function
|
| ||
| Hey Xaron, not as good as function pointers but a good alternative ;) Thanks for this hint |