%operation concept (SDL script)
This topic applies to TDK SDL script extensions. For more information, see Overview of SDL script extensions for TDK (SDL script).
SDL Script Extensions for TDK:
%operation MyOp1 (%string A, %object B)
...... operation body ......
%endoperation
%operation MyOp2 (%string A, %object B) %return %numeric
...... operation body ......
%return 1
%endoperation
...... calling the operation ......
%numeric Result
MyOp1 ("TheStringValue", %current)
Result = MyOp2 ("TheStringValue", %current)
In TDK it is possible to declare operations with parameters (functions) and optional return value, with the following syntax:
%operation <Operation Name> (<calling parameters in Type Name format separated by ",") [%return <return type>]
.
%numeric RET (depends on <return type>)
.
. ...operation body...
.
%return RET
%endoperation
After an operation has been declared, it can be called with the standard C-like syntax, as illustrated in the example above
Implications about parameters
Parameters are always passed as reference. Changing a parameter value from within the operation body results in a value modification in the caller's context:
%operation MyOp (%string A)
A = "string1"
%endoperation

......
%string X
X = "string2"
MyOp (X)
%message X
The above example prints string1
An operation can be declared with zero or more parameters; however, the quotes in the operation declaration are still mandatory: "%operation OpWithNoParams ()", "%operation OpWithNoParamsButReturningNumeric () %return %numeric"
Implications about %return <expression> statement
%return <expression> is used for returning a value from within an operation body.
%return statement must be the last statement in an operation body
%return can be used just for value returning operations, that is, those operations that have a definition like "%operation MyOp (...parameters...) %return %numeric"
Use of %return on operations that do not return a value is not allowed.
Note that theability to call modules and passing/accessing parameters with the %param, %getparam, %setparam etc. keywords is supported by TDK as well.
Variable declaration inside an operation
Variables declared inside an operation are local by default. So inside an operation body:
%localstring A
%string B
Both statements have exactly the same effect (apart from the variable names).