Include mid-type
BlitzMax Forums/BlitzMax Programming/Include mid-type
| ||
I'd like to split a type over several files - with different sets of methods in different files.Type A include "A animation methods.bmx" include "A etc methods.bmx"... End Type But I get this error on compile: "Compile Error: Syntax error in user defined type declaration" I thought include was a preprocessor which copies the text from the other files into place? Is there no way around this problem? |
| ||
cant put an include inside a type...thats crazy talk; it would try to include files every time you created a type. |
| ||
Stack-trace information on the BlitzMax debuger and compiler is file-based, so it is not possible to make imports inside a type or function. |
| ||
So one way to get around this is to extended types... (use sprite just for an example)Type TSprite ... EndType Type TAnimSprite Extends TSprite ... EndType Type TGameCharacter Extends TAnimSprite ... EndTypeThen these extended types can be spread across several files. |
| ||
That's ugly as well, if you ask me. Couldn't there just be some mechanism added to BMxax like in c++ where you can define functions and methods outside of the Type scope? |
| ||
No there can't as the compiler / parser would become more complex and there definitely are more important things that an eye candy feature that users of real IDEs (-> code folding) don't need at all. I still don't understand why users of BM, even thought it has been out for 2 years, still try to use the Blitz3D style of programming instead of getting used how modern languages work. |
| ||
Why not use an external preprocessor? Sure, it wont compile directly inside the IDE, but a simple batch file or an open terminal fixes that. GCC has one, though i prefer M4. (both come with MinGW) |
| ||
Will, what do you want to do this for? Knowing why you want to do it might help people suggest other ways. Personally, I think allowing includes in a type is horrible but I might be missing a very good reason why it's needed. |
| ||
Type Animal Field HP:int Method Feed() HP:+1 End Method End Type Animal::Method Kill() HP=0 End Method Shouldn't be too hard to make, no? |
| ||
If that code was not already wrong even thought its just a showcase, it perhaps would make sense ;-) A correct implementation of such a feature would look similar to function pointer declaration already allows you to work (and basically could be done with methods and reflection as well): Type Animal Field HP:int Field Kill() Method Feed() HP:+1 End Method End Type Method Animal::Kill() HP=0 End Method but in the end, the implementations must still be in the same file. |