Difference between revisions of "LavishScript:Script Syntax"

From Lavish Software Wiki
Jump to navigation Jump to search
 
(28 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== Overview ==
+
#REDIRECT [[LavishScript:Language and Engine Overview]]
Scripts consist of <tt>comments</tt>, <tt>functions</tt>, <tt>code blocks</tt>, <tt>commands</tt> and <tt>control structures</tt>.
 
 
 
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 [[LavishScript:Preprocessor|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 (<tt>;</tt>) 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 [[Command:If|If]] and [[Command:While|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 <tt>control structures</tt>.
 
 
 
==== Conditional ====
 
* [[Command:If|If]]..[[Command:Else|Else]]
 
==== Repetitive ====
 
* [[Command:Do|Do]]..[[Command:While|While]] ([[Command:Break|Break]], [[Command:Continue|Continue]])
 
==== Selective ====
 
* [[Command:Switch|Switch]]..[[Command:EndScript|EndScript]] ([[Command:Break|Break]], [[Command:Case|Case]], [[Command:Default|Default]])
 
 
 
 
 
== 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 ==
 
* [[LavishScript]]
 
* [[LavishScript:Preprocessor|Preprocessor]]
 
* [[LavishScript:Designing Scripts|Designing Scripts in LavishScript]]
 

Latest revision as of 04:36, 16 May 2006