Contents | Index | < Browse | Browse >
2.6 Newtypes (Complex Types)

  Newtypes are compositions of primitive and/or other Newtypes. In
  other literatur you might find them as "structures" or "complex types".
  
  They are defined using the "NEWTYPE" keyword and listing the field with name
  and type:
  +-----------------------------------------------------------------------------
  | 
  | NEWTYPE name 
  |   varname.t
  |   ...
  | End NEWTYPE
  | 
  +-----------------------------------------------------------------------------

  A field in the type is addressed by using "\" (back slash):
  +-----------------------------------------------------------------------------
  | 
  | NEWTYPE myType
  |   x.f
  |   y.f
  | End NEWTYPE
  |
  | DEFTYPE.myType test
  | test\x = 1
  | test\y = 2
  | NPrint "x is ",test\x," and y is ",test\y
  | 
  +-----------------------------------------------------------------------------

  If a field is written without type, it "inherits" the type from the previous
  field. The first field needs to have a type explicitly mentioned.
  
2.6.1 Multi Assignments

  When assigning values, multiple fields can be filled at once by starting with
  one field and give several values separated by commas. Be careful that the
  order you specify the values is exactly matching the order of the fields in
  the Newtype. This is a potential source for bugs, e.g. when the Newtype is
  reordered.

  Example:
  +-----------------------------------------------------------------------------
  | 
  | NEWTYPE myType
  |   x.f : y
  | End NEWTYPE
  |
  | DEFTYPE.myType test
  | test\x = 1,2
  | 
  +-----------------------------------------------------------------------------
  Note: "y" is of type float, because the previous field "x" is of type float.
  Note: Like expressions, the multiple fields can be in the same line,
        seperated by a ":" (colon).  
  
2.6.2 Arrays in Newtypes

  Newtypes can contain one-dimensional arrays. In contrast to normal arrays,
  they are written using square brackets.
  +-----------------------------------------------------------------------------
  | 
  | NEWTYPE myType
  |   x.f[10]
  | End NEWTYPE
  |
  | DEFTYPE.myType test
  | test\x[0] = 1
  | test\x[1] = 2
  |  
  | NPrint test\x[0]
  | 
  +-----------------------------------------------------------------------------
  

Contents | Index | < Browse | Browse >