Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

High Level Constructs

unit

Units

Units are groupings of functions and

also

variables appearing in .mez files.

They can be thought of as modules or namespaces. A

Mezzanine script

Helium app must have at least one unit.

Unit

The unit keyword must be followed

with

by a unique unit name.

Units are defined as follows.

 

Info
  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. }
Status
colourBlue
titleHeads Up
 

Code Block
languagejava
titleUnit Example
linenumberstrue
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;
}

 

 

Info

Objects, enums and validators are global, so they can optionally be in a separate source code file without a unit.

 

Mez File Comments

Two types of comments are supported

Single line comments

 

Info// date tstamp = System

: single line comments and multi-line comments:

Code Block
languagejava
titleSingle Line Comments Example
linenumberstrue
// date tstamp = System.now();

//
 decimal rand = System
 decimal rand = System.random();

 

And multi-line comments:

 

Info/* date tstamp = System
Code Block
languagejava
titleMulti-line Comments Example
linenumberstrue
/* date tstamp = System.now();
decimal rand = System

decimal rand = System.random();
 
 */

 

 

 

 

 

Variable and Function Scope

This unit has one unit variable named myVar. This variable has unit scope and can be accessed by any function in the unit. The unit also has a function named factorial. A unit must have at least one function. To refer to a unit’s member functions or variables from another unit, you have to use the scope operator

 

Info
  • unit TestUnit;
  •  
  • void test() {
  •     MyUnit:myVar = "New string value!";
  •     int f = 

    (the colon).

    Code Block
    languagejava
    linenumberstrue
    unit TestUnit;
    void test() {
        MyUnit:myVar = "New string value!";
        int f = MyUnit:factorial(5);
    
    }

     

     Note: Unit variables cannot be in line initialized when they are declared. The following code will not compile

     

    Info
    1. unit MyUnit;
    2.  
    3. string myVar = "some value"; // this is not a legal statement
     

    :

    Code Block
    languagejava
    linenumberstrue
    unit MyUnit;
    
    string myVar = "some value"; // this is not a legal statement

     


     

    Additional Mentions and References