Include mid-type

BlitzMax Forums/BlitzMax Programming/Include mid-type

Will(Posted 2007) [#1]
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?


smilertoo(Posted 2007) [#2]
cant put an include inside a type...thats crazy talk; it would try to include files every time you created a type.


ziggy(Posted 2007) [#3]
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.


REDi(Posted 2007) [#4]
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
...
EndType
Then these extended types can be spread across several files.


CS_TBL(Posted 2007) [#5]
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?


Dreamora(Posted 2007) [#6]
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.


grable(Posted 2007) [#7]
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)


tonyg(Posted 2007) [#8]
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.


CS_TBL(Posted 2007) [#9]
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?


Dreamora(Posted 2007) [#10]
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.