Function Handles Example please?

BlitzMax Forums/BlitzMax Programming/Function Handles Example please?

Sanctus(Posted 2008) [#1]
Could anyone write a function handle example please?
I knew blitz could do that but I can't remember the syntax and can't find anything.
Thank you


fredborg(Posted 2008) [#2]
You mean callbacks?

Like:
Global myCallback:Int( value:Int )

Function setCallback( c:Int(v:Int) )

	myCallback = c

EndFunction

Function test:Int( v:Int )

	If myCallback
		Return myCallback(v)
	Else
		Return 0
	EndIf
	
EndFunction


'
' The function we'll use as a callback
'
Function bla:Int( in:Int )
	Return in*2
EndFunction

'
' Testing...
'
Print "Before callback has been set"
Print test( 1000 )

'
' Setting the callback
setCallback( bla )


Print "After callback has been set"
Print test( 1000 )



Sanctus(Posted 2008) [#3]
Yeap thx that's exactly what I wanted.