Information Technology Reference
In-Depth Information
network. There are two key principles at work in this
corresponding script code.
is called from the relevant object, and not as a global
function. Thus, this function is called by first specify-
ing the path to the object that owns the function (and
will be responsible for making the new object, which
it will subsequently “own' as one of its elements), and
then specifying the function and its arguments. The al-
ternative, more traditional way of doing this would be
to have a global function called New , which would be
called with the path to the object that will own the new
object as its first argument:
B.3.1
Object Paths
The first principle is that objects are specified with a
path , where each element in the path is separated by a
period (.). All paths start with the root object, which
is represented graphically with the PDP++ Root win-
dow. This root is represented in the script code by
the initial period (.) before .projects... . If you
want to be very explicit, you can also write this as
root.projects... . The subsequent elements of
the path are specified in terms of particular members
(aka fields, data items, sub objects) of a given object.
Thus, the root object has as one of its members the
projects group, where projects are located. Since
almost everything is contained within a project, all of
the script lines start with .project .
Because you could have multiple projects, you need
to specify which one you want. This is done us-
ing the bracket syntax [0] after .projects .The
0 indicates that you want the first project (which is
the only one in this case). Thus, we can understand
.projects[0].networks in the script as specify-
ing the networks member of the first project. There
is a shortcut mechanism built into the script, which al-
lows you to only specify the distinctive parts of the
path. Thus, it will automatically look into the first el-
ement of every group and search for the member name
you give it in the path. So, this first line could have
been written .networks->New(1, Network); ,
because the networks member is assumed to be the one
in the first element of the .projects group, which is
correct in this case. In general, it is safe to skip the ini-
tial .projects[0] , and often the .networks[0]
too, but beyond that you might end up not giving
enough distinctive information, or pointing to the wrong
place, so it is safer just to be explicit.
New(.projects[0].networks, 1, Network);
The advantage of the object oriented approach is that
it allows each object to have its own custom set of func-
tions, and to do different things with standard functions
if necessary. Instead of having a big if-then statement
in the global New function to handle each different type
of object that could be created, the object-specific New
function just implements the code relevant to that par-
ticular object.
To complete our analysis of this one line of
script code, note that the arguments to the function
(1, Network) correspond to the values in the new
object dialog box. In this case, and in general, there is a
close homology between the structure of things and ac-
tions taken in the interface, and the corresponding script
code. Finally, observe that there is a semicolon (;) at the
end of the entire line — this is necessary to indicate that
this is one complete statement or program action.
The next line of code in the script is similar to the
first, except that it is creating layers in the newly created
network:
.projects[0].networks[0].layers->New(3,\
LeabraLayer);
Note that the backslash ( n ) in the above code and in
subsequent examples indicates that the following line
should continue at the end of the current line — these
lines are too long to be typeset as one line in the topic,
but should appear as one line in the program, without
the n .
B.3.2
Object-Oriented Function Calls
The second principle is that the script language is ob-
ject oriented , which means that the function that is be-
ing performed (i.e., New , which creates new objects)
B.3.3
Assigning Member Values
The next line after that is somewhat different, in that
it does not involve a function (e.g., New ), but instead
Search WWH ::




Custom Search