Skip to content

Instantly share code, notes, and snippets.

@Sei-Lisa
Last active October 15, 2017 16:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sei-Lisa/5d5db979d1e4901c5385ac59ed0870cf to your computer and use it in GitHub Desktop.
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
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