preprocessor directives added easily
BlitzMax Forums/BlitzMax Programming/preprocessor directives added easily
| ||
Hi, just tested one quite easy way to add preprocessor directives to bmax. adding just a couple of lines to bmk, you can use: #define DEBUG #ifdef DEBUG 'DEBUG CODE HERE #elseif 'RELEASE CODE HERE #endif (also #include "myheader.bmx" works) this is just quick test. and it works. if you want to test this. bmk_make.bmx: line 311 add: Sys("gcc -E -x c -P -w -traditional-cpp -o "+cquote(src_path+"_")+" "+cquote(src_path)) 'Preprocess file RenameFile (src_path,src_path+"__") 'backup original source RenameFile(src_path+"_",src_path) 'rename preprocessed file CompileBMX src_path,obj_path,opts 'compile "preprocessed source CopyFile(src_path+"__",src_path) 'restore original source DeleteFile(src_path+"__") 'delete backup this is not perfect right now.. but this can be somethig. :D also you cant use blizmax labels, because them start with # and gcc will give error (also using original bmaxIDE you will need to modify ide source(if using Options Auto Capitalize).. #else and #endif are corrected to #Else and #EndIf... but this is interesting way to preprocess any code... Thanks goes to 'dragon' in Monkey forums where he/she mentioned this idea... http://monkeycoder.co.nz/Community/post.php?topic=4148&post=44876 Last edited 2012 |
| ||
Why not use ?Debug and its counterpart, ?Not Debug... |
| ||
Maybe "debug" was just an example. aaand... you can use some "debug-logging" without using an debug-compilation. also: define DOLOGGING #ifdef DOLOGGING print blabla #endif should save some lines of code which would else get processed within the app's loops. bye Ron edit: even nicer is define DOLOGGING #ifdef DOLOGGING Function Log(value) 'do something awful complex and slow End Function #else Function Log(value) 'do nothing End Function #endif Last edited 2012 |
| ||
Cool :-) Do I want to add this to BMK NG? Hmmm... |
| ||
IMO, I would avoid the C syntax. Isn't it just as easy to add a few new preproc words to bmk??define DOLOGGING Function Log(value) ? DOLOGGING 'do something awful complex and slow ? Not DOLOGGING 'other stuff ? return End Function Having a few extra preproc keywords (even if they were hardcoded like: user1, user2 etc) Would be super helpful. For example if you want to build a game client and game server from the same source tree. Last edited 2012 |
| ||
Well, the advantage of using GCC's preprocessor is that it's really old, and rather good at what it does. Sure, it requires an intermediate step of source-code generation, but this can be hidden away in the build process. I don't think adding new ? directives is as easy as you think. |
| ||
I had a play with ? directive in bmk and it seemed that the actual directives themselves also need to recongised by bcc, ie the directives are actually a part of the bcc compiler, not bmk. I could be wrong as it was late and I was bored :D So correct me if I am wrong though. This looks like a great solution as I don't use the # identifier in BMax. Thanks! Last edited 2012 |
| ||
cool that you liked.. let's see whaT WE GET..... Brucey do your best :D |
| ||
For example if you want to build a game client and game server from the same source tree. This should never happen. option a: server is run dedicated - should only share what is needed to get everything managed (client authentification, game data verification) option b: server is one of the clients aka game master - in this case each client should be able to handle that. back to topic... will have to check this out after that special days :D bye Ron |
| ||
Wouldn't faking the preprocessor stuff like this cause the debug output to give the wrong line numbers; so the line numbers won't line up with the source code? If not, then this would be a great feature. |
| ||
Bumping this thread. I really need a pre-processor for logging. Is there an easy way to set that up? |
| ||
I can really use this for building different versions of my application, like demo mode, etc. |