LavishScript:Script Syntax

From Lavish Software Wiki
Revision as of 21:33, 25 May 2005 by Eleven (talk | contribs)
Jump to navigation Jump to search

Overview

Scripts consist of comments, functions, code blocks, commands and control structures.

All scripts must have a function called main. The main function will be executed when the script is run, and any extra parameters given to the RunScript command will be passed to the function.

Preprocessing

Before a script is used, it is sent through a preprocessor. The preprocessor's job is to take text (a single script file), and replace, remove, or insert parts, including other files. For example, the preprocessor allows the creation of entire sections of code that are conditionally used in the final version used by the system. Preprocessing directives and macros are recognized only by the preprocessor, not by the actual script or command interpreters.

Comments

Comments must be on their own line, never at the end of another line. Any line that starts with a semi-colon (;) is considered a comment, and will not be handled by the script.

Functions

Functions are defined like so:

function MyFunc1()
{
  commands
}
function MyFunc2(parameter1,parameter2,parameter3)
{
  commands
}
function MyFunc3(string parameter1,int parameter2)
{
  commands
}

Functions may have any number of parameters, and each will default to the string type if a type is not given. Each function must have its own code block. The function ends either at the final }, or from a return command. Either way, execution proceeds after the previous call statement, or ends the script if the function is main.

Code Blocks

Code blocks are defined by having a { to begin, and } to end, on their own lines. These blocks are used to define the scope of a function, and are also used by certain commands such as If and While.

Commands

Commands are simply LavishScript commands, as may be entered in a console or command file.

Control Structures

Some commands available only to scripts change the flow of execution of the script. For example, a command may cause a block of code to repeat, or only be executed in a certain condition. These commands along with the code blocks they affect make up control structures.

Conditional

Repetitive

Selective


Examples

Example 1

Obligatory "Hello World" script

function main()
{
   echo Hello World
}

Example 2

A fairly pointless script that demonstrates looping, functions, variables, data methods

function MyFunction(int Count)
{
  return -${Count}
}

function main()
{
  Declare Count int 1
  do
  {
     call MyFunction ${Count}
     echo Count: ${Count} ${Return}
  }
  while "${Count:Inc}<=10"
}

See Also