HANDLE/OBJECT analogy for Blitzmax?

BlitzMax Forums/BlitzMax Programming/HANDLE/OBJECT analogy for Blitzmax?

Mongoose(Posted 2013) [#1]
Hello all,

I'm porting some of my old Blitz3D code that uses a ton of HANDLE/OBJECT calls, and i'm curious if there's an analogy / way to emulate it within Blitzmax? I've tried a few things, but they ended in misery for me. Any clue as to if this is possible, or am I going to have to reimagine how some of this is written?


Yasha(Posted 2013) [#2]
It is possible, but the short answer is that it's a really bad idea because it messes with the garbage collector.

Depending upon how you were using the Object/Handle calls, there are several ways you might want to go about rewriting it.

-- if you were using them to store objects in a bank... just use an array, as in BlitzMax you can pass arrays around as freely as banks anyway

-- if you were using them to store objects of multiple types in the same collection (an array, bank, list, whatever)... BlitzMax will let you store them all as the base type "Object", so there's no need to fake polymorphic behaviour with integers

...and various other things. Object/Handle are almost always used in B3D to make up for features that BlitzMax has built-in, so you'll see much better results if you use the "real" version of whatever the original code was trying to do (and learn something new at the same time!).


Who was John Galt?(Posted 2013) [#3]
Yasha +1.

Avoid that type of thing like the plague in Max.


ziggy(Posted 2013) [#4]
Yasha +1 too.
Also, use Strict or SuperStrict code ALWAYS


skidracer(Posted 2013) [#5]
These are the functions used by the MaxIDE Import bb code option which take advantage of auto type conversion in functions to do their magic.

	Function HandleToObject:Object(obj:Object)
		Return obj
	End Function
	
	Function HandleFromObject(obj:Object)
		Local h=HandleToObject(obj)
		Return h
	End Function



Mongoose(Posted 2013) [#6]
Thanks for the responses, guys. I know it's bad practice, and leaves a lot of garbage behind, but I mainly need this for legacy purposes. I tried converting all of it, but somewhere down the line it broke how it functioned, which took me back to square one. My desk has a permanent mark where I've been bashing my skull against it.

I've also tried the Import BB function, but it can't make heads or tails with some of the crazy array magic I pulled off. This is one moment where younger me thinks I'm doing amazing things, while older me wants to punch him.