| Expression statement | block {} Statement | Branch Statements | Loop Statements | Type Declaration | Variable Declaration | Synchronize Statements | With Statement | Using Statement | Type Alias |
Type declarations introduces new Variable in a Script
See also: Types.
VarDecl
: [ TypeName ] VarName [ '=' Expression ] ';'
;
A component type name identifies a enumeration
or class name with optional namespace/package name.
The class name resolution works in following steps:
CfgScript first looks in the TypeAlias tables if there is
any alias for given TypeName.
If an alias was found the type name will replaced with the
original type name.
See also: Type Alias.
Next step is to search in the declared using
in the scope.
See also: Using Statement.
If the type was not found in the further steps
the type are searched in the list of loaded
classes.
If no namespace name is given it search through
all namespaces to find the given class.
If the same namespace exists in different namespaces
the first found class will be choosen (no warning, no error!).
If it the class cannot be found it uses
the ClassLoader to try to load the class.
For more information about ClassLoader please refer to Library.
The scope of variables are limited by their block:
int i = 42; // is global scope
{ // Block, introduce new scope
int i = 1; // overwrite variable for this scope
int j = 2; // j is only valid in this scope
i == 1;
j == 2;
} // leaving scope
i == 42; // i is now global scope
j == 2; // invalid because j is not longer valid
|
Typed variables has a defined type
int i; // i is an int
acdk.lang.StringBuffer sb; // sb is StringBuffer
i = 3; // OK
i = 4.3; // OK, convert automatically
i = "A Text"; // throws ClassCastException
sb = new acdk.lang.StringBuffer(""); // OK
sb = new Integer(2); // throws ClassCastException
|
In the default mode ad hoc variables usage, without
a defined type of the variable is also possible:
i = 2; // i is a any-type (DmiObject) containing a byte
i = "Text"; // now i contains a string
Any j = 2; // Explicit Any type
|
See also: PragmaStatement.
See also: Any Type.
The Script Environment contains following global variables.
-
- interpreter: instance of current acdk::cfgscript::Script.
- false: Boolean(false)
- true: Boolean(true)
- Nil, nil, null: Nil object
- out: acdk.lang.System.out
- err: acdk.lang.System.err
- File_separator: acdk.io.File.separator
- File_pathSeparator: acdk.io.File.pathSeparator
|