user types and pointers
BlitzMax Forums/BlitzMax Programming/user types and pointers
| ||
I want to initialize a user type with another user type. The problem is that I only have the memory adress of the other user type. How do I solve this?Type user_type Field data1,data2 EndType Local another_user_type_address:Int=0000101010 'some adress Local u_type:user_type = user_type Varptr another_user_type_adress '?! |
| ||
I have an adress stored as an int. How to I get a user type to equal the user type variable located at that adress? |
| ||
The easiest way is probably via some C glue:' declared in BlitzMax Import "glue.c" Extern Function objectFromAddress:Object(address:Int) End Extern ... // glue.c #include "brl.mod/blitz.mod/blitz.h" BBObject * objectFromAddress(int address) { return (BBObject*)address; } But unless you know what you are doing, you probably don't want to be storing Object addresses somewhere outside of the GC. Btw, and you'd be better storing the value as a pointer (eg. Byte Ptr) rather than an Int - just in case you ever want to support 64-bit apps in the future. |
| ||
Testing in progress :) |
| ||
You're my hero. It works. Just for everyone else(or me from the future) you have to replace 'Object' with your user type name. |
| ||
BinaryBurst: you have to replace 'Object' with your user type name No -- you better cast to your object. local MyEntity:TEntity = TEntity( objectFromAddress(address) ) local MyGUIEntity:TGUIEntity = TGUIEntity( objectFromAddress(address) ) if not MyEntity then print "object from address is not existing or not of type TEntity" if not MyGUIEntity then print "object from address is not existing or not of type TGUIEntity" if not objectFromAddress(address) then print "there is no known object at this address" Also: like Brucey told you, you better replace that int-"pointer" to a "Byte Ptr". bye Ron |
| ||
Like Derron said, just cast to the type you want. |