This program transpiles custom preprocessor directives into TorqueScript code. It mainly allows for the usage of macros, like in C/C++.
It's mainly targetted towards Blockland, but it can be used for any software that runs on TGE 1.3 or before.
The Blockland Preprocessor does not read .cs files! It reads .blcs files instead.
All files must start with the ##blcs directive.
You define macros with ##define like so:
##define MAX_INT_VALUE 999999You then use macros like this:
if ($someVar > #MAX_INT_VALUE)
{
error("Max integer value reached!");
}Multiline macros are supported with brackets #{ ... #} like so:
##define myMultilineMacro
#{
echo("line 1");
echo("line 2");
echo("line 3");
echo("line 4");
#}You can define macros that take in arguments. To use arguments in your macro, prefix them with #%:
##define add(num1, num2) #%num1 + #%num2Then use them like so:
return #add(1, 2);The above will expand to:
return 1 + 2;If you want to surround your macro with parentheses you'll have to surround them with brackets so as to not confuse the parser (or yourself):
##define myParenthesizedMacro #{ (getRandom(1, 100) * getRandom(1, 100)) #}Use ... when defining a macro to declare it as variadic (it must be the last "parameter"), and use #!vargs to insert said arguments into your macro:
##define error(errorCode, ...)
#{
$LastError = #%errorCode;
error("ERROR: ", #!vargs);
#}
#error(0xD34DB33F, "Failed to reticulate splines!", "Very Not Good.");The above will expand to:
$LastError = 0xD34DB33F; error("ERROR: ", "Failed to reticulate splines!", "Very Not Good.");To prepend a comma before inserting the arguments, use #!vargsp. If no variadic arguments are passed in, no comma will be inserted.
You can also insert the number of arguments passed in with #!vargc.
Use #@ for macro argument concatenation.
##define DefineEnemyDataBlock(name, health, silly)
#{
datablock PlayerData(Enemy_ #@ #%name)
{
health = #%health;
isSilly = #%silly;
};
#}
#DefineEnemyDataBlock(Orc, 50, true)The above will expand to:
datablock PlayerData(Enemy_Orc) { health = 50; isSilly = true; };You can also use #@ for string literal concatenation, as long as they use the same quote character.
For example:
##define concat(str1, str2) #%str1 #@ #%str2
echo(#concat("Hello ", "there!"));The above will expand to:
echo("Hello there!");The same will work for two tagged strings.
However, if you try to use a tagged string and a regular string, it will not work:
echo(#concat('Hello ', "there!"));The above will expand to:
echo('Hello '"there!");To use macros from other files, you can do so like this:
##use "relative/path/to/file.blcs"Please note that this does not execute the file—it simply processes the file and makes the macro definitions available.
You can insert the line number into your macros with #!line.
If you want to insert it elsewhere into your code, you can just ##define line #!line and then use #line anywhere.
There are two ways to use this program: either as a typical console program, or as a command-line interface.
To use it normally, just drag a .blcs onto the program. Make sure any imported macro files are in the correct folders.
You can also use it as a command-line interface: usage: BLPP path [-h] [-d] (-w | -X) [-q] [-e]
-h, --help Displays help.
-d, --directory Specifies that the path is a directory.
-w, --watch Watches a directory for changes, and automatically processes any files that were changed.
-q, --quiet Disables all messages (except command-line argument errors).
-e, --output-empty Forces creation of processed files that are empty.
-X, --cli Makes the program operate as a command-line interface that takes no keyboard input and closes immediately upon completion or failure. (Incompatible with --watch)
To build for Windows:
- Open in Visual Studio 2022 (or later)
- Right-click on the
BLPPproject and click "Publish" - Create a new profile with the "Folder" target
- Set the "Target Runtime" to
win-x64 - Click "Show all settings" and set "Deployment mode" to
Self-contained - Click "Save" and then click the large "Publish" button in the top right corner
To build for Linux:
- Install the .NET 8.0 SDK with
sudo apt-get update && sudo apt-get install -y dotnet-sdk-8.0 - Navigate to the repo folder
- Build the project:
dotnet publish -a x64 --os linux -c Release --sc
To build for macOS:
- Don't.