Silly simple thing but...
BlitzMax Forums/BlitzMax Beginners Area/Silly simple thing but...
| ||
Hi, this bit of pseudo kinda explains what Im after but I can't find the syntax(if it exists)...type Tmyinttype:int global x:Tmyinttype = 3 x would be of type integer. I don't want to create a custom record or object, in the traditional sense(no using 'new')... |
| ||
Why do you want to do this? If you want to extend the int type, I'm afraid you can't do it directly because ints aren't objects in bmax. |
| ||
I had to wrap an Int into a type (as a field) once in order to use it with the collision layer (which only returns objects and I just needed an Int) |
| ||
It's not clear to me what you're trying to do. Are you trying to define Tmyinttype as a new name which you can use instead of int but which will operate identically? Like a TypeDef in C++? There used to be a command called Alias which I think did that, but it's been removed so I can't test it. |
| ||
Well I have to wrap a header, the header has types like this, TSoundEntity, TObjectHandle, etc... all are simple integers. These forms of 'user defined types' are used mainly for readability. So you can create an array of TSoundEntity for example. Actually most, if not all languages I have come across use the term 'User Defined Type' to cover this, as well as class definitions and record types... I am finding it quite a surprise to see its not covered in BlitzMax? Well, if its not available, then there's nothing I can do... at least I can stop scratching my head! :D |
| ||
someone said this feature used to be available so maybe you could check out older product updates... maybe the very first one? |
| ||
Can't it be done from c++? |
| ||
The basic datatypes - int, byte, etc have to be compatible with CPU registers. CPU's don't know anything about custom types, they only work with basic numbers, or numbers interpreted as addresses/pointers. You wouldn't be able to store a custom type in the cpu, as such, and have the CPU understand that it represents an integer. That's why you have to wrap them in a type if you need to use them that way. |
| ||
Um, the type I was discussing would be converted back to an integer by the preprocessor before the compiler even gets warm. This is just a question of syntax, its a pretty standard thing that is easy for a compiler developer to implement. |
| ||
As said by Grey Alien, the only way to do it - is like in java - creat an Integer Type containing a single int field... JavaDoc for Integer: "The Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int." That what you have tried is a sort of C-Style Typedef, and thats not working in MAX |
| ||
Yet again, operator overloading would've saved the day! |