Using Data Items
Once a variable has been declared, it may be referenced. The reference to a variable may occur in the sense of retrieval, where the variable may be thought of as a source of values to be used. When referenced in this way, a variable behaves as though a corresponding literal had been used in place of the reference. This usage of variables is permitted anywhere in SDL, providing the variable being referenced has already been declared. Thus, it is possible to declare a <scalar>:
scalar max_color(255);
Then immediately use it to declare another variable, e.g.
triple white( max_color, max_color, max_color );
Indeed, this is exactly how normal use of SDL will proceed, with the declaration of basic building blocks followed by even larger pieces until all the items needed for the model have been defined. Thus, variables of the elementary data types (i.e.., scalar, triple, CV, filename, shader, texture, array) will commonly be refer-enced as part of the declaration of other variables, or in the specification of liter-als. References to vari-ables of the data types for "primitive objects" (i.e.., light, patch, face) will normally be in the MODEL section of SDL where they will be used to create an instance of the object represented by the variable. Some of the data types provided in SDL are complex compositions of many com-ponents.
Some operations are defined for all data types, while other operations depend upon the data type. There are common operations which are allowed for vari-ables of all data types except as noted below. These common operations are:
- a variable may be printed,
- a variable may be assigned the value of another variable of the same type,
- a variable may be assigned the value of an array element of the same type,
- a variable may be assigned the value of a literal of the same type,
- a variable may have its values assigned to another variable of the same type,
- a variable may have its values assigned to an array element,
- a variable may be referenced wherever a literal of the same type may be used.
An exception to the above is that there is no such thing as a literal (to serve as the source of an assignment) for some data types, namely: shaders and transforma-tions. Note that printing means that the values of the components defining the variable will be output to "stderr", not that some graphic rendition will be at-tempted. Note that operations on a scalar are the same as previous versions of SDL. This includes general usage in arithmetic expressions (see "expressions" be-low). While there is no such thing as a literal transformation, a variable of type transformation can have the cur-rent model transform assigned to it.
Arrays are special. While the above operations are valid and true for arrays, they don't give the full picture. Therefore, the operations will be reconsidered here for ar-rays.
- An array may be printed. This means that each element in the array will be printed as though it were an independent variable.
- An array may have the contents of another array assigned to it. If the two arrays have the same number of elements, then the assignment takes place on an element by element basis. If the two arrays have a different number of elements, it is considered a syntax error, and execution terminated.
- A variable or a literal of any data type may be assigned to an array element. No checking of the array element's previous contents is made, so the new value may be a different type from the previous.
- An array element may be used in place of a variable. The type of the present contents of the array element is considered the type of the element. That is, type checking of elements is performed at reference time (not assignment).
- Note that arrays have undefined element contents and undefined element types (unless an initial value is specified when the array is declared) until the element is given some value by assignment.
aliasdocs@aw.sgi.com
Copyright © 1997, Alias|Wavefront, a Silicon Graphics Company. All rights
reserved.