Extern native code

Monkey Forums/Monkey Programming/Extern native code

Raz(Posted 2012) [#1]
I think I get it, but just want to make sure I am doing this right. When targeting BlitzMax, I would like to call the HideMouse() function, so I am doing the following.

#If TARGET="bmax" Then
    Extern
        Function HidePointer:Void() = "HideMouse"
        Function ShowPointer:Void() = "ShowMouse"
#Else
	Function HidePointer:Void()
		
	End
	
	Function ShowPointer:Void()
		
	End
#Endif


and then calling HidePointer() at the end of the OnCreate() method. If for whatever reason I choose a difference target, it will just call the empty function.

I've tested it, and it works. But I just want to make sure this is the correct way of doing things. Ta :)


Tibit(Posted 2012) [#2]
I think that is a good question. While I can't say I have explored all options, at this stage that is similar to how I would do it.

There is always the question of how to handly empty methods or errors on unsupported targets. Should we force the calling code to use #If TARGET = or should we omitt using a empty function.

If someone has some clever methodlogy or programming practice for extern native code, I'd also be happy to hear more about it.


AdamRedwoods(Posted 2012) [#3]
that's how it's done.