Alexandria is currently undergoing
maintenance and will be back shortly!

Take the Tour | Site Map

Chapter 1. Using the Standard Subs

Table of Contents

Script Template

Script Template

With the 2.2.0 release of Codename Alexandria Standard Subs, a script template has been introduced. This template is to help script authors in getting started in using the Standard Subs in an efficient and robust manner.

The template file is named scriptTemplate.txt and located in the /src/ directory:

It starts with the usual Lexia header. Note that it not necessary to repeat this part in your own script. The $Id ... $ markup is of no use but with our internal Version Control solution.

; Alexandria Project, a standard subs library. 
; Copyright (C) 2001-2003 The Codename Alexandria Team. 
; Template for script using the Alexandria packages 
; $Id: using-subs.xml,v 1.2 2003/07/29 08:28:05 scriptfellow Exp $ 

First thing, you must initialize EasyUO event system. Even though your script doesn't use any event command, the sub that it will call will require the event system to be available.

;==== Start Codename Alexandria header ==================== 

Next you should specify the path to the installed Standard Subs release. You may either use

  • an absolute path like C:\EasyUO\Alexandria\2.2.0\

  • an relative path, starting from your script's directory, like ..\Alexandria\2.2.0\

;---- relative/absolute path to packages ------------------ 
   set %_subsPath ..\src\ 

Each of the Standard Subs package has an initialization part. This part is typically executed only once, on first call of the package.

If for any reason you would like to force a package initialization whenever the script is restarted - i.e. to re-check the Don't Move Cursor option - you may uncomment the appropriate line below:

;---- uncomment next lines to force initialization -------- 
;   deleteVar subsInitialized 
;   deleteVar binaryInitialized 
;   deleteVar setupInitialized 
;   deleteVar stringInitialized 

Next is definition of convinient shortcuts for every package. Only the shortcut for subs.txt is enable below. Uncomment the appropriate lines if you'll be using additional packages.

;---- shortcuts to packages ------------------------------- 
   set %_subsTxt %_subsPath , subs.txt 
;   set %_binaryTxt %_subsPath , binary.txt 
;   set %_setupTxt %_subsPath , setup.txt 
;   set %_stringTxt %_subsPath , string.txt 

Your script may require some subs or features that weren't available in earlier release of the Standard Subs. The code below is to check that the version of installed packages meet your requirements.

In the code below, only the main package subs.txt is being checked for a version of 2.2.0 or more. Uncomment the appropriate lines if you will be using additional packages.

Note that subs.txt should always be checked and that versions prior 2.2.0 will be rejected.

;---- test packages version ------------------------------- 
   set %return #false ; necessary to detect versions prior Alexandria 2.2.0 
   call %_subsTxt requirePackage subs 2 2 0 
   if ! %return 
      display ok Couldn't find a compatible version of the subs.txt library 
;   call %_binaryTxt 
;   call %_subsTxt requirePackage binary 1 0 0 
;   if ! %return 
;   { 
;      display ok Couldn't find a compatible version of the binary.txt package 
;      halt 
;   } 
;   call %_setupTxt 
;   call %_subsTxt requirePackage setup 1 0 0 
;   if ! %return 
;   { 
;      display ok Couldn't find a compatible version of the setup.txt package 
;      halt 
;   } 
;   call %_stringTxt 
;   call %_subsTxt requirePackage string 1 0 0 
;   if ! %return 
;   { 
;      display ok Couldn't find a compatible version of the string.txt package 
;      halt 
;   } 

Because speed is sometimes critical, the Standard Subs have an internal mechanism to increase execution speed of CPU intensive tasks. By default, it is assumed that the number of lines per cycle in your script is 10 and that CPU intensive subs should execute 100 lines per cycle.

If you need to use different settings, uncomment the lines below and set the relevant values.

;---- set default and maximun lines per cycle speeds ------ 
;   call %_subsTxt setDefaultLinesPerCycle 10 
;   call %_subsTxt setMaxLinesPerCycle 100 
;==== End Codename Alexandria header ====================== 
;---- your script starts here -----------------------------