Callback code..

Monkey Forums/Monkey Programming/Callback code..

Paul - Taiphoz(Posted 2012) [#1]
is something like this possible in monkey.

[monkeycode]
method SomeThing(x,y,result())
do something.
'at the end have the callback function called ( result() )
end method

function result()
do something with the results of which ever method called me.
end function
[/monkeycode]


ziggy(Posted 2012) [#2]
[monkeycode]
'this is like a standard callback "signature"
Interface Callable
Method Action()
End

'this is the implementation of a callback
Class Result Implements Callable
Method Action()
Do Whatever here
End
End

.....

'This is an usage example:
Method SomeThing(x,y, whatever:Callable)
Do Stuff...
whatever.Action()
End
[/monkeycode]

You can have a global instance of each implementation, as we can't have instanceless methods on interfaces.


Paul - Taiphoz(Posted 2012) [#3]
oh that helps a lot thanks mate.