contents   index   previous   next



Structures

 

Structures are created dynamically, and their elements are not necessarily contiguous in memory. When ScriptEase encounters a statement such as:

 

foo.animal = "dog"

 

it creates a structure element of foo that is referenced by "animal" and that is an array of characters. The "animal" variable becomes an element of the "foo" variable. Though foo, in this example, may be thought of and used as a structure and animal as an element, in actuality, foo is a JavaScript object and animal is a property. The resulting code looks like regular C code, except that there is no separate structure definition anywhere. The following C code:

 

struct Point 

{

   int Row;

   int Column;

}

 

struct Square 

{

   struct Point BottomLeft;

   struct Point TopRight;

}

 

void main()

{

   struct Square sq;

   int Area;

   sq.BottomLeft.Row = 1;

   sq.BottomLeft.Column = 15;

   sq.TopRight.Row = 82;

   sq.TopRight.Column = 120;

   Area = AreaOfASquare(sq);

}

 

int AreaOfASquare(struct Square s)

{

   int width, height;

   width = s.TopRight.Column  s.BottomLeft.Column + 1;

   height = s.TopRight.Row  s.BottomLeft.Row + 1;

   return( width * height );

}

 

can be easily converted into ScriptEase code as shown in the following.

 

function main()

{

   var sq.BottomLeft.Row = 1;

   sq.BottomLeft.Column = 15;

   sq.TopRight.Row = 82;

   sq.TopRight.Column = 120;

   var Area = AreaOfASquare(sq);

}

 

function AreaOfASquare(s)

{

   var width = s.TopRight.Column  s.BottomLeft.Column + 1;

   var height = s.TopRight.Row  s.BottomLeft.Row + 1;

   return( width * height );

}

 

Structures can be passed, returned, and modified just as any other variable. Of course, structures and arrays are different and independent, which allows a statement like the following.

 

foo[8].animal.forge[3] = bil.bo

 

Some operations, such as addition, are not defined for structures.

 


Passing variables by reference