Last active
October 15, 2017 16:17
-
-
Save Sei-Lisa/5d5db979d1e4901c5385ac59ed0870cf to your computer and use it in GitHub Desktop.
LSL Trick: Do something when the file is run through a preprocessor, and something different otherwise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string dummy="/*\ | |
"; | |
// insert here code that will only be compiled when the preprocessor is active | |
#include "debug.h" | |
/*/""; // separator line | |
// insert here code that will only be compiled when the preprocessor is inactive | |
debug(string s){llOwnerSay(s);} | |
// */ | |
/* Rest of file here */ | |
default{timer(){}} | |
// It takes advantage of a bug in the grammar, where a double quote is ignored | |
// if there is a backslash at the end of a line before the next double quote. | |
// As a side effect, it defines a string variable 'dummy', | |
// which will be "/*" if there was a preprocessor, and "" | |
// otherwise. | |
// Tested with LSL PyOptimizer, mcpp, GNU cpp, Firestorm preprocessor, lslint, and plain SL. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment