Preprocessor update

Status
Not open for further replies.

Plombo

OpenBOR Developer
Staff member
As of r3802, the script preprocessor has been updated.  The biggest change is the addition of support for the #if and #elif directives, which were the only major C preprocessor feature that were missing before.  They are supported fully, so you can use any constant expression that you could use in an #if or #elif directive in a C or C++ program.

With this change and the bugfixes to existing preprocessor functionality in 3802, the OpenBOR preprocessor is actually quite close to a compliant C99 preprocessor.  The only differences are:
  • No support for #pragma.  Not that you care.
  • #include paths can only be specified with quotes, not angle brackets (<>).  The angle bracket syntax is being reserved for possible use in the future.
  • Support for the concatenation operator in macros ("##") doesn't quite work for complex cases, though I'll be surprised if anyone needs it for OpenBOR.

I used my old test program from 2010 with a slightly modified version of the preprocessor to parse the standard C library headers on my Linux system, and it produces the correct output (same as mcpp) for every header I tested (stdio.h, stdlib.h, string.h, stdint.h) except math.h, which only fails because of the problem with concatenation mentioned above.  That should be more than sufficient as practical testing. :)
 
Your preprocessor is the bomb. I'm actually in the midst of writing a tutorial on use of it; mostly focusing on constants but applies to the whole thing overall.

DC
 
Could some platform specific compiling switches be added?
For example:

#if WINDOWS
    printText("Save directory: ./Saves/"+pakname);
#elif ANDROID
    printText("Save directory: /mnt/sdcard/OpenBOR/Saves/"+pakname);
#elif PSP
    blahblah
#else
    printText("Unknow platform");
#endif

 
utunnels said:
Could some platform specific compiling switches be added?
For example:

Yes, it would be quite simple to do that.  We could create a function in openborscript.c that adds built-in macro definitions to a pp_context, which could include conditionally defining platform macros.  If we wanted to do a fancier built-in macro system (or allow for growing room), we could use the currently reserved angle bracket syntax of #include to let the user include different built-in macro definitions, like #include <platform> or #include <constants>.

My main concern with a macro for each platform, though, is that people might start misusing them such that, for example, a mod doesn't work on Linux that would otherwise.

utunnels said:
#if WINDOWS
    printText("Save directory: ./Saves/"+pakname);
#elif ANDROID
    printText("Save directory: /mnt/sdcard/OpenBOR/Saves/"+pakname);
#elif PSP
    blahblah
#else
    printText("Unknown platform");
#endif

See, even your example code does it. :P

If we do add built-in macros, one of them should definitely be the saves directory.
 
Status
Not open for further replies.
Back
Top Bottom