Inno Setup Preprocessor: User Defined Functions

You can define user defined functions.

A user defined function declaration consists of a formal parameter list and an expression. That expression is evaluated when the function is called (see below). The result of the function call is the result of the expression. The expression can contain parameter names, they are treated as usual variables.

The formal syntax of a user defined function is provided in define and ISPPBuiltins.iss contains many example functions.

Please note that there must be no space between the function name and opening parenthesis.

Actual parameters for parameters declared as by-reference must be modifiable l-values (in other words, other defined variables or expressions that evaluate to l-values). If the expression modifies by-reference parameter, the variable that is passed as this parameter gets modified. By-value parameters can also be modified by the expression (using assignment operators), but this modification doesn't affect the value of a variable which could be passed as this parameter.

Though a user defined function can only contain one expression, sequential evaluation operators (comma), assignment operators (simple and compound) and conditional operators (?:) can be used to build more complicated functions.

Local array

In context of the expression, an additional array named Local is valid. Its elements can be used for temporary storage and reusing values in sequential expressions. Values stored in Local array are neither preserved from call to call (including recursive), nor are they accessible from anywhere except the expression.

#define DeleteToFirstPeriod(str *S) /* user defined function declaration */ \
  Local[1] = Copy(S, 1, (Local[0] = Pos(".", S)) - 1), \
  S = Copy(S, Local[0] + 1), \
  Local[1]