?Win32_or_Linux
BlitzMax Forums/BlitzMax Beginners Area/?Win32_or_Linux
| ||
Hello! Just a silly question: I'm currently writing BlitzMAX applications which shall run on all three supported platforms (Win32, MacOSX and Linux). As not every module is available for all platforms (e.g. Jasper, OGGSaver, MiniB3D) I have to use "compiler switches" within my code: ?Win32 ... ?MacOS ... ?Linux ... ? My question is now: as I sometimes have larger code blocks which may run on *two* platforms of the three supported, is there any way to "combine" two branches - in a way similar to ?Win32, Linux ... ? or ?not MacOS ... ? Thanks in advance for your help! |
| ||
I don't there is I'm afraid. I've had to copy code that's the same for another platform for each of the platform's that require it. |
| ||
Well, I could use "import", of course, and stuff my code blocks into a separate file - such that only the "import" statement has to be copied. But I want to avoid having to break my code into multiple files. |
| ||
It is a bit of a pain, having to specify each one separately, especially if two of them are going to contain the same piece of code. But that's what you have to do at the moment. |
| ||
alternative: do the common code just without any ? and use a ?MacOS block to redo the stuff for MacOS Alternative take the BMK sources and add a ?NotMacOS directive |
| ||
alternative: do the common code just without any ? and use a ?MacOS block to redo the stuff for MacOS You can't do it like that. If you don't specifically state what's for Windows and Linux, then it will get compiled along with any modifications you want to make for the Mac, when compiled on a Mac. You would only do it the way you're suggesting if you want the code for Windows/Linux to also run on a Mac, just with a little something extra. |
| ||
Depending on what you want to do this is no problem. As ?WinAndLinux clearly implies that it is API independent, I don't see a reason a independent block followed by a Mac block to modify some variables should not work. The content of type instances and variables is the only thing that would differ in this case, right? beside OSX api dependent stuff that would be held within the ?MacOS block |
| ||
I think the best idea would be to split up your project into a main file and imported file or something like that and just do ?Win32 Import "file_win32_or_linux.bmx" ?Linux Import "file_win32_or_linux.bmx" ?MacOS Import "file_macos.bmx" ? |
| ||
You could also call a given function that will do what you want for any specific OS if you don't want to split it up into files: ?Win32 DoThisLinWin() ?Linux DoThisLinWin() ?MacOS DoThisMacOnly() ? Function DoThisMacOnly() . . . End Function Function DoThisLinWin() . . . End Function |
| ||
Thanks for all the hints... but since I have to define (platform-dependent) types and functions, many of the ideas do not apply. Unfortunately, I'll have to split my code and "import" those sources only, which belong to a given platform. Extending BlitzMax's functionality is not an option for me right now (I'm already busy implementing other BlitzMax modules) |