#strict
With activated #strict
various old scripting inaccuracies will be ignored and proper type checking can be applied.
Declaration
The #strict directive has to be placed at the beginning of each script. #include or #appendto will follow the strictness of the script to be included or to which is to be appended.
Results
#strict 2
With activated #strict 2
various old scripting inaccuracies will be ignored and proper type checking can be applied.
Declaration
The #strict 2
directive has to be placed at the beginning of each script. With #include
or #appendto
the strictness of the script in which a function was defined is used.
Results
-
&&
and ||
do not evaluate the second operand if the result is already determined by the first operand.
-
return
, if
and while
only accept one parameter. Also some other expressions which used to cause a warning only are now no longer accepted.
-
==
and !=
do not compare identity of two values, but their type and contents. Example: [1,2]==[2-1,2], "Hallo"=="Hallo" and CastInt(CLNK)!=CLNK.
- Function and variable names may only contain the character a-z, A-Z, 0-9, and '_'.
-
eq
, ne
, S=
are not available anymore. eq
and ne
can now be used as names of functions or variables or a variable of name S
can be assigned via S=42;
.
#strict 3
Any new script should be #strict 3
. In this way further old scripting inaccuracies will be ignored, even stronger type checking can be applied and new language features are activated. Scripts without #strict 3
are accepted only for backwards compatibility reasons.
Declaration
The #strict 3
directive has to be placed at the beginning of each script. With #include
or #appendto
the strictness of the script in which a function was defined is used.
nil
#strict 3
introduces the new value nil
. It represents undefined and unset values and is of type any
. Furthermore, 0 and false
are not implicitly converted to any
anymore but keep their respective type. This makes it possible distinguish undefined values from 0 and false
, for example for defining default parameter values that can be overriden by 0 or false
. nil
is unequal to any possible value of any other type, including 0 and false
. Thus, it suffices to check x != nil
to tell if a value has been defined. Anyway, !nil
is true
.
Because 0 and false are not any
anymore, they can not be converted to other types like string
, object
, array
or map
which would trigger an error. Consequently, function arguments that should be passed as unset also have to be set to nil instead of 0.
The ? modifier
Likewise #strict 3
introduces a new modifier which allows "safe" navigation. ? is prepended to the navigation operators to obtain one of the following constructs: ?.
, ?[i]
, ?->
or ?->~
. By using the ? modifier, those accesses do not trigger an error if the underlying value is nil. Instead, the whole expression is aborted and evaluates nil. Because by using this modifier the expression is assumed to return nil sometimes, the expression result is always dereferenced. This is due to the fact that using the result of a ?-modified expression in a reference context would defeat the purpose of the modifier, because in the case nil is returned it would error anyway.
Further Effects
- Maps and the .-navigation syntax are activated
-
Permissions are also checked when using the
->
syntax to call a function, given that the target script is also at least #strict 3
.
-
global->
and global->~
become available.
-
false != 0
and true != 1
Sven2, Juli 2001
Günther, Dezember 2007
Der Tod, Oktober 2019