Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: Predefined Events Up: Events Previous: Shared Clients


Script Clients

In addition to running separate programs or shell commands as clients, you can also use Glish scripts as clients in other Glish scripts. These scripts are referred to as ``script clients''. You create script clients using the client function, much as you might expect:

    sc := client("glish myscript.g")
In general you use the same argument syntax as when running a script directly (See § 13.1, page [*]).

In every Glish script, whether run as a script client or not, Glish provides a global variable called script (See § 10.11, page [*]). If you run the script directly (not as a script client), then script has the boolean value F. If however you run the script as a script client then script is an agent record (See § 7.2.2, page [*]), and can be used in whenever and send statements to receive and send events. You can also determine whether a script is being run as a script client by checking whether ``system.is_script_client'' is T or F. (See § 10.11, page [*] for further description of the system global variable).

For example, the following script computes a ``timestamp'' string (perhaps to be used in constructing archive file names). If invoked directly the script prints the current timestamp and exits. But if invoked as a script client, it waits for get_timestamp events. Upon receiving one it generates a timestamp event with the current timestamp and goes back to waiting for the next get_timestamp event.

    # Script to compute timestamps.
    # Run independently, prints current timestamp
    # and exits. Run as a script client, responds to
    # "get_timestamp" events by fetching the current
    # timestamp and sending it out in an "timestamp"
    # event.

    if ( system.is_script_client )
        {
        whenever script->get_timestamp do
            script->timestamp( current_timestamp() )
        }

    else
        # Run independently.
        print "Current timestamp:", current_timestamp()


    func current_timestamp()
        shell("date+%a-%h-%d-%T")

If this script were in a file timestamp.g, you could then use it in another script as follows:

    timestamp := client("glish timestamp.g")
    ...
    # Return current timestamp.
    func stamp()
        {
        timestamp->get_timestamp()
        await timestamp->timestamp
        return $value
        }

Script clients behave, in general, identically to regular clients. In particular, they respond to and generate the predefined events defined in § 7.11, page [*] below.

Script clients can also be shared by multiple users. This is done by simply adding one of the following statements to the beginning of the script:

The shared script processes events as usual; the only difference is that the events are coming from multiple interpreters. Currently, there is no way for the script to select a specific interpreter to send the event to. This will be fixed in a future release.


next up previous contents index
Next: Predefined Events Up: Events Previous: Shared Clients   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15