Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Button handy
blanktrue
color#0052CC
nameSend Feedback
linkhttps://docs.google.com/forms/d/e/1FAIpQLScmToBe3vynAlb5fdKwCGxYqnTbDc66sIBgeecG2BuFDuHc7g/viewform?entry.2002826954=Inclusions+-+15487128
widthauto

Info

This page explains how to use include files in Simple Issue Language (SIL) programs.

The include statement in SIL lets you import and execute code from other SIL files. This can improve readability and make your code more manageable.

Tip

You can use the include

statement

 statement to

import

:

  • Import entire libraries of

UDRs.

Syntax

include
  • User-defined functions (UDFs).

  • Break down large programs into manageable components.

  • Share common functionality across multiple scripts.

Contents:

Table of Contents
minLevel1
maxLevel3
outlinefalse
styledefault
typelist
printabletrue

Syntax

Inclusions in SIL use the following syntax:

Code Block
include "path/to/file.incl";

Here are some key points to remember when using inclusions in your SIL programs:

  • Include statements must

be the first statements in
  • appear at the beginning of your program, before

the definition of UDRs.
Info

For more information see  Structure of a SIL™ program.

The provided path may
  • any user-defined functions definitions.

  • File paths can be relative or absolute.

If relative, it is
  • Relative paths are resolved relative to the defined

'
  • sil.home

' environment variable, usually the 'silprograms' directory.Variable Visibility
  •  environment variable (typically the silprograms directory in the SIL Manager.)

  • To maintain consistency, consider using the .incl extension for included files.

Info

For more information, see  Structure of a SIL™ program.


Variable visibility

There are two categories of variables you can use in the included programs.

You can use two categories of variables in the included files:

Variable category

Definition

Example

Local

Variables

These are the variables you define in the body of the included program.

These can be used

They are accessible throughout the included file, the main program,

as well as in your SIL™

and any other program that uses the included

the file

code.

file.incl
Code Block
// Define a simple increment function
function increment(int x) {
  return x + 1;
}

// Create and initialize a variable using the function
// This variable will be accessible to any program that includes this file
number a = increment(0);  // a is now equal to 1
program.sil
Code Block
// Import the contents of file.incl
include "file.incl"; //resolved relative to the 'sil.home'

// We can use both the 'a' variable and increment() function defined in file.incl
number b = a + increment(2); 
//
we can use the
 Here's what happens:
// 1. 'a'
variable here!

Notice the use of variable a in the SIL™ program even though it was declared in the included file. Also notice the use of the increment() UDR that was defined in the included file as well.

Global Variables
 has value 1 from file.incl
// 2. increment(2) returns 3
// 3. b becomes 1 + 3 = 4

Global

These are the variables that are already defined and can be used right away (issue fields and

customfields

custom fields). You can use these anywhere in your code without having to declare them.

file.incl
Code Block
function getKey() {
  return key;    // 'key' is a global issue field
}

Header

Guards

New to Power Script 5.8.x, header guards protect your scripts from scenarios where through nested include files the same file might accidentally (or intentionally) have been included more than once.

Image Removed

In the image above we can see that both include file A and include file B are using include file C. Perhaps include file C was a collection of helpful functions that could be reused in both file A and file B. Without header guards file C would need to be removed from one of the other files, A or B, otherwise there would be an error. Now, with header guards, the first occurrence of the include files will be loaded and subsequent occurrences will be ignored.

Contents

toc

guards

Header guards prevent duplicate inclusion of the same code, which is particularly important when you have complex include relationships. They automatically handle situations where the same code might be included multiple times (accidentally or intentionally) through different paths.

Here’s how header guards work:

  • When you include a file, SIL first checks if this file has already been processed.

  • If it's the first time, the code is included.

  • If the file has been previously included, SIL skips it.

  • This happens automatically - no additional syntax is required.

Example

In this scenario the main.sil program uses A.incl and B.incl files. Both are using include file C.incl. Even though file C is referenced twice (through both A.incl and B.incl):

  • it will only be loaded the first time it's encountered

  • it will be automatically skipped on subsequent includes, preventing any errors in your program

Code Block
main.sil
│
├── A.incl
│   └── C.incl    // First time included
│
└── B.incl
    └── C.incl    // Skipped, already included