2.2. Executable Programs

There is currently no facility for embedding Gamma source code into a stand-alone Gamma executable. However, it is possible to create a Gamma program which appears to be a stand-alone executable to the user. This is done by using the shell's #! directive at the top of the Gamma file. Simply include the line indicating the full path for your Gamma program, for example:

    #!/usr/cogent/bin/gamma
    	  
If using Gamma with Photon, you should use:
    #!/usr/cogent/bin/phgamma
    	  
Then change the permissions on the Gamma file to be executable. The Gamma file can now be run directly as if it were a stand-alone executable. The directive must appear as the first line of the program, and it must reference the actual Gamma executable, not a link.

The following example program will print the famous "Hello world" message to the screen:

    #!/usr/cogent/bin/gamma
    
    princ ("Hello world\n");		
    	  

There is no requirement for a function named main. If a function with the name main is defined, then Gamma automatically starts to execute that function. Thus, the result of the following program:

    #!/usr/cogent/bin/gamma
    
    function MyPrint()
    {
        princ ("Hello world\n");
    }
    
    function main()
    {
        MyPrint();
    }
    
    MyPrint();
    		
is that the function MyPrint will be executed twice.

Command line arguments can be passed to the Gamma program using the list variable argv. For more details see Tutorial I.

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