User:Kadah Coba/Firestorm Preprocessor

From Second Life Wiki
< User:Kadah Coba
Revision as of 00:08, 1 September 2015 by Kadah Coba (talk | contribs) (Created page with "= Firestorm Preprocessor = A few of the preproc tricks that may be useful. No real organization, just mainly notes. Since most of the FS preproc functionality comes via Boos...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Firestorm Preprocessor

A few of the preproc tricks that may be useful. No real organization, just mainly notes.

Since most of the FS preproc functionality comes via Boost::Wave, pretty much an standard C style preproc stuff seems to work. Like many of these [1] [2].


Relative includes

If you have a large project hosting on disk that is being included, you can reference includes local to the file instead of using static paths for everything.

#include "./classes/lawmower.lsl"


Turn tokens in to strings

Useful for adding debugging to macros.

#define printlist(list) llOwnerSay(#list + ": " + llDumpList2String(list,", "));

list somelist = [1,2];
printlist(somelist);

//Output: somelist: 1, 2

Works with any token too.

#define PRINT_TOKEN(token) llOwnerSay(#token + " is " + (string)(token))
integer x = 1; integer y = 2;
PRINT_TOKEN(x + y);
//Preproc output: llOwnerSay("x + y" + " is " + (string)(x + y));
//Output: x + y is 3


Multi-line macros

Using the escape character (\) at the end of a line on a macro will wrap lines. This is very helpful for saving memory on not using sub functions but still having the organization/reusability. More helpful on memory saving from not using sub functions that pass large amounts of variables or lists, or when more than one return is needed since passed variables on macros are like pointers.

#define OS(a,b) if (a > 1) {\
  llOwnerSay((string)a);\
} else {\
  llOwnerSay((string)b);\
}
OS(1234,5678);
//Preproc output: if (1234 > 1) {  llOwnerSay((string)1234);} else {  llOwnerSay((string)5678);};

Note: Single-line comments (\\) will cause undesired effects. Use block comments (/* */) instead with the escape character at EOL.


Construct variable names and such

Say you need to concatenate strings in to a variable name.

#define printstring(a,b) llOwnerSay(a ## _ ## b)
string test_string = "Something";
printstring( test, string );
//Preproc output: llOwnerSay(test_string);
//Output: Something