LScript User Guide
Next Section Previous Section Table of Contents Index Errata

Inside LScript

In the following sections we will cover details of LScript through examination of the language syntax, variables, control structures, commands and functions.

LScript Script Structure

An LScript is structured much like a C program. Each script that you write can have as little as one procedure, or as many as you need (and your computer's memory allows). Each LScript must contain at least one procedure, and it must be labeled as "main."

     main
     {
         ...
     }

The "main" Procedure

Execution of an LScript is always controlled by the main() procedure. All processing within your script can take place within this single procedure, or you may use the main() procedure to selectively execute other procedures belonging to your script. These other procedures can take the form of built-ins (those that are internal to the LScript Scripting Plugin), or those that you (or others) have defined as scripting procedures. These non-internal scripting procedures are often referred to as "user-defined procedures."

User-defined Procedures

A user-defined procedure can be created within your script by declaring a name for your procedure, followed by an opening brace ('{') and terminated by a closing brace ('}'). An alternate syntax can be used that replaces the opening brace with the keyword begin and the closing brace with the keyword end.

User-defined procedures can also optionally accept one or more calling arguments. These argument declarations follow the procedure name, and are prefaced by a colon (':').

User-defined procedures also have the ability to return one or more values to the caller by using the return command. A return command can return two or more values by separating them with a comma (','). When a user-defined function returns more than one value, the receiving variable would ideally be of type array. However, the LScript language does not enforce this, so the receiving variable, if not an array, will be assigned the first return value while all remaining values are discarded. If a variable of type array is used, it is not required to be of the same size as the return argument count of the user-defined procedure. Those return values whose position exceeds the array size will simply be discarded.

By way of example, let's create a user-defined function to select a particular value if the first argument is non-zero, and select another value if it determines that the first argument is equal to zero. We'll call the new procedure which, and it could be written in the follow manner:

     main
     {
         ...
         t = which(val1,val2,val3);
         ...
     }

     which: v1,v2,v3
     {
         if(v1)
          return(v2);
         else
          return(v3);
     }

Libraries

User-defined procedures can also be housed in LScript libraries. LScript libraries are much like LScripts with the exception that they cannot contain a main() function, nor can they declare global variables.

When you direct LScript to process a library for your script, you employ the library directive. When encountered, LScript will scan through the specified library looking for user-defined procedures that satisfy unresolved references made in your primary script. Only those user-defined procedures that satisfy an unresolved external reference will be loaded into your script's run-time space for execution. Other library procedures that have no relevance to your script will be ignored by LScript (you can modify this behavior by using the loadall pragma directive, which is discussed later in this document).

Libraries are accessed by placing a library command in your script at the global level (i.e., outside all declared functions), and following it with the name of the library file. For example,

     library "mylib.lib";

     main
     {
         ...
     }
The example LScript file2.ls, include on your distribution diskette, illustrates the use of LScript’s library feature by loading a library file (file2.lib) to accomplish its task. Library files can have any filename you wish. LScript does not enforce any sort of naming convention where libraries are concerned.

LScript also allows you to specify default libraries that will be loaded automatically when each script is executed.


Next Section Previous Section Table of Contents Index Errata
© 1996 Virtual Visions, Inc.
© 1997 NewTek, Inc.