enum fake out
BlitzMax Forums/BlitzMax Programming/enum fake out
| ||
I came up with, what I think, is the best alternative for proper enum vars in BlitzMax. Yes, you still have to number everything by hand, but at least you can use them as you would in a .NET language...Type EStatus Global Open = 0 Global Closed = 1 Global Waiting = 2 End Type MyStatus = EStatus.Closed Print MyStatus WaitKey |
| ||
You know, I suggested this in the last Enums thread. Might want to put 'Final' after EStatus so that it can't be inherited. |
| ||
Congrats. This just occurred to me this morning so I figured I'd throw another stone in the pool. No biggie. |
| ||
Hi, Using Consts instead of Globals will be safer and more efficient. |
| ||
Having actual enums in the language would be the ideal solution. :) |
| ||
Agree with Warren here. How hard could it be to add them? Heck, you could probably just preprocess the code to spit out a type with constant fields and it'd still work. PLEASE ADD ENUMS. That's my request- and since it's my birthday soon, I may as well put it in ;) |
| ||
how about a small program to generate consts with seq nums? |
| ||
There are a hundred work arounds. However, the best solution remains for Mark to add them to the language. As Noel pointed out, it's as simple as added a preprocessing step to convert them into const vars internally. Should be quick and painless to add to the compiler... |
| ||
Mark, any thoughts on adding these to the language? |
| ||
How hard could it be to add them? Heck, you could probably just preprocess the code to spit out a type with constant fields and it'd still work. Then they wouldn't be typesafe tho', would they? |
| ||
That doesn't make any sense. The compiler preprocesses them into const lines before beginning compilation - it's the exact same effect as if I had typed in the const lines myself. |
| ||
Then they wouldn't be typesafe tho', would they? It's a bunch of constants- does it really matter? |
| ||
That doesn't make any sense. The compiler preprocesses them into const lines before beginning compilation - it's the exact same effect as if I had typed in the const lines myself. An enumerator can be used for more than just 'runtime constants' you know. It's a bunch of constants- does it really matter? No it isn't, and yes it does. |
| ||
Perhaps it can in other languages, but what says that a bmax enumerator has to be anything other than compile-time constants? |
| ||
Perhaps it can in other languages, but what says that a bmax enumerator has to be anything other than compile-time constants? Because otherwise you could just as well write them all by hand, or auto-generated. |
| ||
Yep. Thing is, Bmax doesn't auto-generate them. /me adds to list of things for pre-processor |
| ||
IMHO the language should have enums Strict and Stricter Stricter is case sensitive. |
| ||
An enumerator can be used for more than just 'runtime constants' you know. Every language I've ever used has one use for the keyword "enum" - a list of automatically generated values (or you can specify them by hand, but that's not the common usage). Which other features are supported that I'm not remembering? Like I said, preprocess the enum list into a list of const lines and then compile my program. Simple, and should take Mark all of 10 minutes. |
| ||
Simple, and should take Mark all of 10 minutes. You have to remember that it took Mark all of- what, 3 years?- to add normal and cube mapping to Blitz3D. What might take you ten minutes may take him a couple years. ;) |