Overview DSL Reference
High Level Constructs
unit
Units are groupings of functions and also variables.
They can be thought of as modules or namespaces. A Mezzanine script must have at least one unit.Unit must be followed with a unique unit name. Units are defined as follows.
- unit MyUnit;
- // Other code follows
- string myVar;
- int factorial(int x) {
- if(x == 0 || x == 1) {
- return 1;
- } else if (x > 1) {
- return factorial(x - 1);
- }
- return 0;
- }
HEADS UP Objects, enums and validators are global, so they can optionally be in a separate source code file without a unit.
object
Indicates the start of an object declaration. Must be followed by a unique object name and attribute block
- object Person
- {
- string fname;
- string sname;
- int age;
- }
persistent
Used to indicate that an object is persistent, must precede the object definition
- persistent object Person
- {
- string fname;
- string sname;
- int age;
- }
The _id attribute is also available from any persistent object. It is a uuid type.
enum
Used to declare an enumeration. Must be followed by an enumID (all caps and underscores)
- enum GENDER
- {
- Male, Female
- }
validator
Used to declare a field validator
- validator FirstnameValidator
- {
- minlen(2); maxlen(250);
- }
- validator AgeValidator
- {
- minval(0);
- }
Flow control
return
Returns the value of the expression that follows from a function
- string getGreeting(string name)
- {
- return Strings:concat("Hello, ", name);
- }
if / else
If statement
- if(name == "Tom")
- {
- Mez:log("Hello Tom!");
- }
- else if (name == "Frank")
- {
- Mez:log("Hello Frank!");
- }
- else
- {
- Mez:log("Hi! Who are you?");
- }
for
For loop