Custom extended print functions - DavidPH/GDCC GitHub Wiki

GDCC allows users to define custom print functions, containing new print specifiers. This is particularly useful for quickly printing structures and printing enumerations with their in-source names.

struct SomeStruct
{
   int i;
   str s;
   fixed f;
}

function void SomeStructPrinter (SomeStruct ss)
{
   // PrintRaw is a special function that doesn't start or end a print, but simply adds to the currently open one.
   // It's primarily used for custom print functions like this.
   // For this example, this is simply the struct's members printed separated by commas.
   PrintRaw(i:ss.i, s:", ", s:ss.s, s:", ", f:ss.f);
}

print CoolPrint
(
   // This defines which function to call to start the print.
   (begin): BeginPrint,

   // And this defines which function to call to end the print. If this
   // function returns a value, that value will be the result of the print.
   (end): EndPrint,

   // This is a macro in <zspecial.acs> which includes all the normal print
   // specifiers. If none of them are desired, this can be omitted.
   ACS_PrintPropertyBase(),

   // Now to add our cool new print specifier.
   // This is the name of a function taking exactly one parameter, which is the object to print.
   ss: SomeStructPrinter

   // Note that the final specifier does not get a comma after it.
);

// Now a function called CoolPrint is available with the above specification.
Script "test" ENTER
{
    SomeStruct myStruct = {128, "gdcc test", 50.2};
    
    // Output: 128, gdcc test, 50.2 are the values in myStruct.
    CoolPrint(ss:myStruct, s:" are the values in myStruct.");
}

In addition to EndPrint, ZDoom has more functions available that change the behavior of the print. EndPrintBold, EndHudMessage, EndLog, EndStrParam, and so on.