Function as argument

Monkey Forums/Monkey Programming/Function as argument

Blitzbat(Posted 2011) [#1]
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!


Warpy(Posted 2011) [#2]
No


Blitzbat(Posted 2011) [#3]
So hopefully mark will implement it. I think it's an important thing


therevills(Posted 2011) [#4]
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


Blitzbat(Posted 2011) [#5]
That was not a good idea to remove them.... What's the reason for removing that feature?


Xaron(Posted 2011) [#6]
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



Blitzbat(Posted 2011) [#7]
Hey Xaron,

not as good as function pointers but a good alternative ;)

Thanks for this hint