Difference between revisions of "LavishScript:Language and Engine Overview"

From Lavish Software Wiki
Jump to navigation Jump to search
Line 16: Line 16:
  
 
=== ANSI-C Comments ===
 
=== ANSI-C Comments ===
ANSI-C comments begin with <tt>/*</tt> and end with <tt>*/</tt>.  This style of comment may begin and end anywhere without restriction, but may not be nested.  For some tips on using ANSI-C comments, see [http://www.jetcafe.org/~jim/c-style.html#Comments Standards and Style for Coding in ANSI C].
+
ANSI-C comments begin with <tt>/*</tt> and end with <tt>*/</tt>.  This style of comment may begin and end anywhere (including in the middle of other lines) without restriction, but may not be nested.  For some tips on using ANSI-C comments, see [http://www.jetcafe.org/~jim/c-style.html#Comments Standards and Style for Coding in ANSI C].
  
 
  /* This is an ANSI-C Comment */
 
  /* This is an ANSI-C Comment */
Line 33: Line 33:
 
  ; This is a full-line comment
 
  ; This is a full-line comment
 
  echo hi; This is NOT a full-line comment
 
  echo hi; This is NOT a full-line comment
 +
 +
== Object type definitions ==
 +
Types of objects can be defined as part of a script.  These object types will only be available for object creation or typecasting within their owning script, but objects of these types can be accessed anywhere within scope of the object.  Object scopes are discussed in the Variables section below.
 +
 +
Object type definitions begin with the keyword <tt>objectdef</tt>, followed by the name of the type of object, such as
 +
objectdef character
 +
Inheritance can be specified by using the keyword <tt>inherits</tt>, followed by the name of the script-defined object type to inherit, such as
 +
objectdef player inherits actor
 +
 +
The lines immediately following the objectdef line describe the contents of the new object type.  They may contain variables, functions, methods, members and atoms.  The contents of the objectdef begins with a line containing only <tt>{</tt>, and ends with a line containing only <tt>}</tt> (referred to as a code block).
 +
 +
The following is an example of a valid, empty object definition:
 +
objectdef player inherits actor
 +
{
 +
}
 +
 +
== Functions ==
 +
== Variables ==

Revision as of 23:19, 18 April 2006

Introduction

LavishScript is designed for a mixed, hostile environment. That is, an environment where objects and types of objects may be forcefully removed without notice by an external source. For example, as part of an addon to a game that was not meant to have addons, with scripts to automate gameplay and such. Safety is ensured by discarding object references after use (as each data sequence is closed).

LavishScript is pre-emptively scheduled and also has a concept of atomic code sequences. Pre-emptive scheduling is necessary to allow a script to run "in the background" iteratively while a game plays, as opposed to a purely event-based paradigm, though it is possible to create fully event-driven scripts as well.

LavishScript's structural syntax is derived from C, with statement syntax derived from command-line interpreters.

LavishScript is object-oriented. Each piece of data is an object, and each type of object (object type, also known as data type) may have various operations or other objects associated with it, by containment or otherwise. Object types can be created via script, or in C++. Object types follow a single-inheritance model (though special handling can be used for object types created in C++ to use any sort of inheritance). Object sub-types can be used to create an object that uses another type (compare to C++ templates), such as a collection of strings.

The Language

Preprocessor

LavishScript includes a built-in preprocessor. The preprocessor's job is to take input (generally a file), and apply given transformations (such as word replacements, macros, pre-selection of portions of code, insertion of additional files, and so on), sending the output to the engine for final processing. See the preprocessor page for a complete reference to the LavishScript preprocessor.

Comments

Comments are a method of introducing plain text into code for human readability, and are completely ignored by the script processor. LavishScript supports two types of comments.

ANSI-C Comments

ANSI-C comments begin with /* and end with */. This style of comment may begin and end anywhere (including in the middle of other lines) without restriction, but may not be nested. For some tips on using ANSI-C comments, see Standards and Style for Coding in ANSI C.

/* This is an ANSI-C Comment */
/********************************
 *                              *
 *          So is this          *
 *                              *
 ********************************/
/*
 * And this
 */

Full-line Comments

Full-line comments begin with a ; as the first non-whitespace character on a line, and end naturally at the end of the line. This style of comment cannot be used in the middle of a line.

; This is a full-line comment
echo hi; This is NOT a full-line comment

Object type definitions

Types of objects can be defined as part of a script. These object types will only be available for object creation or typecasting within their owning script, but objects of these types can be accessed anywhere within scope of the object. Object scopes are discussed in the Variables section below.

Object type definitions begin with the keyword objectdef, followed by the name of the type of object, such as

objectdef character

Inheritance can be specified by using the keyword inherits, followed by the name of the script-defined object type to inherit, such as

objectdef player inherits actor

The lines immediately following the objectdef line describe the contents of the new object type. They may contain variables, functions, methods, members and atoms. The contents of the objectdef begins with a line containing only {, and ends with a line containing only } (referred to as a code block).

The following is an example of a valid, empty object definition:

objectdef player inherits actor
{
}

Functions

Variables