HandleFromObject - HandleToObject ?

BlitzMax Forums/BlitzMax Programming/HandleFromObject - HandleToObject ?

Woah! This is a weird feature:
Type GameObject
	
	Field msg:String

	Method Yell()
		Print msg
	End Method
	
	Method getSelf:GameObject()
		Return Self
	End Method

	Function getObj:GameObject(obj:GameObject)
		Return obj
	End Function
End Type

Local obj:GameObject = New GameObject
	obj.msg = "WIN!?!?!!"

Local idx:Int = obj.getSelf()    ' Turns object into a handle
Local b:Byte Ptr = Varptr(obj)
	Print idx
	Print Int(Varptr(b)[0]) 'Notice the difference in the printed values
	
Local obj2:GameObject = GameObject.getObj(idx) ' Turns handle into an object
obj2.Yell()

( http://www.blitzbasic.com/Community/posts.php?topic=41621#486966 )