Common Functions for Any Program (in lib/common.g)

Cogent Tools Demo and Tutorials: Version 4.0
Prev |  | Next

# Chapter 9. Common Functions for Any Program (in `lib/common.g`)

Any function in the demo that can be used in Linux, QNX 4, QNX6, GTK and Photon is put in the `lib/common.g` file. This helps avoid duplication and facilitates maintenance of the code. Some functions in the `lib/common.g` file are specific to one program in the demo (such as the Controller, Log, or History), and are thus are documented with that particular program. The functions documented in this chapter are those from `lib/common.g` that are used by several or all of the programs in the demo.

For more information on common and abstracted functions, please refer to Section 3.1, File Overview.

# 9.1. Requiring OS-Specific Libraries - `lib_require`

Since this demo runs in three different operating systems, each program needs to know which OS is running, so it can load the appropriate library functions. The actual loading functionality is provided by the Gamma `require` function.

       /*--------------------------------------------------------------------
        * Function:    lib_require
        * Returns:     t or nil
        * Description: Finds the name of the current OS, and requires (loads)
        *              the library files specific to that OS.
        *------------------------------------------------------------------*/
       function lib_require ()
       {
         if (_os_ == "Linux")
           require("lib/linux.g");
         else if (_os_ == "QNX4")
           {
             require("lib/qnx.g");
             require("lib/qnx4.g");
           }
         else if (_os_ == "QNX6")
           {
             require("lib/qnx.g");
             require("lib/qnx6.g");
           }
       }

       lib_require();

Prev | Home | Next
Tutorial Two | Up | Starting Programs - `program_startup`

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.