2005/5/10

     
 

CfgScript include other script files

artefaktur

| IncludeStatement | Pragma weak/strong | Pragma cast |

With the include preprocessor statement other .csf files can be included into another script file.


Content of this chapter:

   IncludeStatement
   Usage
   Using ClassLoader instead of include
   Differences between ClassLoader and include



 IncludeStatement

IncludeStatement
: '#' 'include' StringLiteral


 Usage

To include other files use the include can be used

#include "MyOtherModule.csf"

MyOtherModule.csf is a normal CfgScript file.
The include statment protects for multiple/recursive includes.
The #ifdef guards, you have to use in C/C++ are not needed.

The include statements search in following file:
  • The directory of the current csf file
  • The Current working directory
  • The pathes in the CSFINCLUDES Environment variable
  • $ACDKHOME/cfg/csf/include
Please refer also to the command line option  -csfinclude / CSFINCLUDES.


Alternativelly also can also be used:

bool noDups = true;
bool changeToDir = false;
interpreter.include("MyOtherModule.csf", noDups, changeToDir);

See also:  acdk::cfgscript::Script.

 Using ClassLoader instead of include

!

If you want to create CfgScript modules with classes, you can load the CfgScript automatically:

// MyScript.csf
// will use the classloader to find and load the script
mytest.MyOtherScript o = new mytest.MyOtherScript();
Please refer to  CfgScript ClassLoader for more information.

 Differences between ClassLoader and include

The include statement works like a C/C++ include statement.
This has consequence, that global variables defined in the included script file is also visible in the script file, which includes the file.
Module variables in scripts, which are loaded via the ClassLoader are not visible outside the module.