Example Serpentine Programs

This directory contains examples written in the Serpentine language that need to be run on a device with the Dalvik or ART virtual machines. They are also used as simple regression tests for any API or compiler breakage since changes to either of these may cause compilation to fail completely.

To compile the examples, invoke the buildall.py script, making sure that the Compiler package directory is in the PYTHONPATH. For example, from the root of the distribution type the following, remembering to substitute your own key and certificate files for the placeholders used:

PYTHONPATH=. Examples/Serpentine/buildall.py <key.pem> <cert.pem> /tmp/packages

Examples can also be built individually. For example:

PYTHONPATH=. Examples/Serpentine/Timers/build.py <key.pem> <cert.pem> \
             /tmp/Timers.apk

Some of these examples are simple tests of functionality; others were written to show how to access the Java and Android APIs using the syntax of the Serpentine language.

More complex examples may be moved to the Demos directory in the future.

Examples

It might be worth starting with the following examples that introduce aspects of the language as well as describing how the Java and Android API are used:

The following examples use more features of the Android API:

Documentation

Some of the examples are documented using inline docstrings. These are processed when the examples are built if the DOCS_DIR environment variable is set to the name of a directory. If an absolute path is not used, the name is interpreted as a subdirectory of the relevant example directory, as in the following example:

DOCS_DIR=docs PYTHONPATH=. Examples/Serpentine/Compass/build.py \
                           <key.pem> <cert.pem> /tmp/Compass.apk

This requires the example's build script to have been written so that it reads the DOCS_DIR environment variable and passes it to the buildhelper.main function. The script uses the gendocs module to create an HTML file in the documentation directory.