Source files and includes

A program can be split over several files. IncludeFile reads another file in at that point, exactly as if its text were written there.

IncludeFile ✅

IncludeFile "Sources\helpers.pbi"

The file is read every time IncludeFile names it.

XIncludeFile ✅

XIncludeFile "Sources\helpers.pbi"

Like IncludeFile, but a file that has already been included (by either command) is skipped. Library files are usually included this way, so that several files can each include what they need without defining anything twice.

IncludePath ✅

IncludePath "Sources\Data"
IncludeFile "Sprites.pb"          ; reads Sources\Data\Sprites.pb

Sets the directory that later includes look in first.

Where files are found

A relative file name is looked for in this order:

  1. the IncludePath directory, if one has been set;
  2. the directory of the main source file (the one given to the compiler);
  3. the directory of the file that contains the IncludeFile.

Both \ and / work as separators. An absolute path is used as it is.

An example

main.pb:

XIncludeFile "strings.pbi"
OpenConsole()
PrintN(Shout("hello"))

strings.pbi:

Procedure.s Shout(s$)
  ProcedureReturn UCase(s$) + "!"
EndProcedure

Compiling main.pb prints HELLO!.

Errors in an included file are reported with that file's name and line number.

File names

The extension makes no difference: .pb, .pbi and .x are all read the same way. By convention, .pbi marks a file that is meant to be included.

Not yet available 🔜

  • IncludeBinary (inside DataSection).
  • C-style #include: it is recognised, and behaves like XIncludeFile, but hasn't been tested.