Conditional compiling

Monkey Forums/Monkey Programming/Conditional compiling

Playniax(Posted 2011) [#1]
I think it would be nice if the programmer could add his own conditional compiling constants like TARGET. I know if a constant is null/false/not defined the code will not make it in the native target but it’s not exactly the same. Why do I think I need this. Well, I would like to do something like this:

Const testMode:bool = true ‘ or another way to declare it.

#If testMode
Global dummy:Dummy = new Dummy
#End

Function BlaBla
End

#If testMode

Class Dummy

Method DoStuff ()
End

End

#End

Or is it only possible but maybe I missed it? What do you guys think?


therevills(Posted 2011) [#2]
The preprocessor has the constant "config" with "debug" and "release" values, so you can do something like this:

#if config="debug"
  Global dummy:Dummy = new Dummy
#end



Playniax(Posted 2011) [#3]
Thanks, it helps but I would like to see it taken a bit further. For example:

Const TWEENING:Bool = True ' not sure this would have to be a constant...

#If TWEENING
tweening version ...
#Else
normal version...
#end

Can be helpful to optimize your code with different 'modes'.

I guess I could hack it but it would be nice if it was official ;)


dawlane(Posted 2011) [#4]
@Playniax
It's funny that you posted this as I was thinking about something along the same lines at the beginning of the week as I needed way to flag exception within my own code when testing but didn't want to add all the debug information that's generated by monkey.


Playniax(Posted 2011) [#5]
Yeah, it could be very useful. I wasn't sure in the beginning to post it but the idea grew on me. I guess I have to settle for constants but you can not use the if/end around fields for example.


TheRedFox(Posted 2011) [#6]
We can always use a macro processor like gpp.

http://www.owl-s.org/gpp.en.html

It didn't compile on Windows out of the box, but after some fiddling, I got it to work my way.

Download from http://philippeback.eu/GPPWindows


Samah(Posted 2011) [#7]
Already discussed here: http://monkeycoder.co.nz/Community/posts.php?topic=1324


TheRedFox(Posted 2011) [#8]
Yep. Just a note: with GPP you can use some other marker than #, so it can be used as a preliminary pass without trouble.

And using ant to do the filtering and all is nice as well.

ANT, Preprocessor, Makefile for GLFW: just a great chain :-)