Object to pointer and back ... ?
BlitzMax Forums/BlitzMax Programming/Object to pointer and back ... ?
| ||
I found this nice solution: /* Simple Functions to translate Object to Pointer and Back */ /* Note Use of char* as pointers */ char* ObjectToBytePtr(char* AObject) { return AObject;} char* BytePtrToObject(char* AObject) { return AObject;} but i looking for a BMX only solution. Howto convert pointer to object (type) back to object (type) ? |
| ||
I don't know why you'd want to do this, but:Private Function i_objptr:Byte Ptr( p:Byte Ptr ) Return p End Function Public Global ObjectToPointer:Byte Ptr(o:Object) = Byte Ptr(i_objptr) Global PointerToObject:Object(p:Byte Ptr) = Byte Ptr(i_objptr) |
| ||
Watch out for Null objects.Function ObjectPointer:Byte Ptr(o:Object) If o=Null Return Null Local p:Byte Ptr p=o p:-8 Return p EndFunction |
| ||
That's something you should probably test for outside of the function. |
| ||
Thanks a lot. |