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.


  1. unit MyUnit;
  2. // Other code follows
  3.  
  4. string myVar;
  5.  
  6. int factorial(int x) {
  7.     if(== 0 || x == 1) {
  8.         return 1;
  9.     } else if (> 1) {
  10.         return factorial(- 1);
  11.     }
  12.  
  13.     return 0;
  14. }

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


  1. object Person 
  2. {
  3.     string fname;
  4.     string sname;
  5.     int age;
  6. }

persistent

Used to indicate that an object is persistent, must precede the object definition


  1. persistent object Person
  2. {
  3.     string fname;
  4.     string sname;
  5.     int age;
  6. }

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)


 

  1. enum GENDER
  2. {
  3.     Male, Female
  4. }


validator

Used to declare a field validator

 

  1. validator FirstnameValidator 
  2. {
  3.     minlen(2); maxlen(250);
  4. }
  5. validator AgeValidator 
  6. {
  7.     minval(0);
  8. }

 

Flow control

return

Returns the value of the expression that follows from a function

 

  1. string getGreeting(string name)
  2. {
  3.     return Strings:concat("Hello, ", name);
  4. }

 

if / else

If statement

 

  1. if(name == "Tom")
  2. {
  3.     Mez:log("Hello Tom!");
  4. }
  5. else if (name == "Frank")
  6. {
  7.     Mez:log("Hello Frank!");
  8. }
  9. else
  10. {
  11.     Mez:log("Hi! Who are you?");
  12. }

 

for

For loop