Importing other Aptilis scripts
2. How to use imports
3. Import conventions
Imports allow you to re-use code and to keep your scripts concise.
The binary distributions of Aptilis do already include a small library of scripts, which you can use in your programs.
Aptilis has adopted the main characteristics of the package model from Java to avoid collisions between the scripts of different people. See Import conventions.
2. How to use imports
- Imports must be situated at the beginning of a program, before sub definitions.
- the syntax of the import statement is:
import dir.subdir.subsubdir.aptilisfile [as synonym]
Specifying a synonym is optional.
- Aptilis tries to follow the java conventions for packets:
Directories must be separated by '.' not:
/ or \
- If the file is CurrencyUtils.e.txt then aptilisfile above must be:
CurrencyUtils not CurrencyUtils.e.txt
- If aptilisfile is MyUtils, Aptilis will look for the following files, in this order:
- Aptilis will look for the file to import from the following directories in this order:
- Directory pointed to by the environment variable APTILISPATH
- Directory where the script is.
- Directory pointed to by the environment variable CLASSPATH (the Java one).
- The current directory - this may be where the interpreter (aptilis.exe) is but not necessarily. Use getCurrentDirectory() to find out where you are!
- Folders containing Aptilis files to be imported, and these Aptilis files may ONLY contain the following charater ranges in their names: a-z, A-Z, 0-9
In other words the following characters are explicitely forbidden: _ - . / \
- File names are case sensitive under Unix, but not under windows. However in any case, RESPECT case.
- Synonyms follow variable name conventions.
They may only contain letters, numbers, underscores, and have to start with a letter.
- Paths in the APTILISPATH follow the same rules as for java's CLASSPATH.
- Paths are separated by ; under windows : under unix.
- Directories in paths are separated by \ under windows and / under unix, etc.
- Directories (that are likely to be files) whose names end in .zip or .jar or .aar (for possible future aptilis archives) are ignored.
- Directories are case sensitive under Unix but NOT under Windows.
3. Import conventions:
Conventions are necessary to ensure that your own "library" doesn't come into conflict with the one of someone else.
- Packages should all have their directory names in lower case
- Filenames and synonyms should start with a capital
- Subs should start with a capital (auxiliary subs may be in lower case)
- Initialisations (global vars) should be done in an "Init" sub.
- Aptilis standard packages are available from apt.
- Any one else's packages should be their domain names reversed.
CNN would be:
SourceForge would be:
You will need a directory structure like this: "./com/myserver/mypackages"
These examples use the standard Aptilis library.
import apt.template.Html as Html
doctype = Html.Get("doctype_4_01_strict") $
title = "Welcome to my Homepage" $
body = "<h1>Hi there!</h1>" $
head = "<meta name=\"author\" content=\"John Doe\">" $
print("Content type: text/html\n\n")
Content type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
<title>Welcome to my Homepage</title>
<meta name="author" content="John Doe">
cookiedata["ip"] = _ENV["REMOTE_ADDR"] $
cookiedata["browser"] = _ENV["HTTP_USER_AGENT"] $
oldcookie = apt.http.Cookie.Get()
if cookiedata["browser"] != oldcookie["browser"] $
print("Hey! You changed your browser!")