To use this website fully, you first need to accept the use of cookies. By agreeing to the use of cookies you consent to the use of functional cookies. For more information read this page.

Official ZPE Programming Environment documentationStructures and classes

A structure is a data type in which many inner values can be specified. It provides a framework for all variables and functions.

YASS
structure person

  $name = null
  $age = 0
  $email = null

  function set($n, $a, $e)
    $name = $n
    $age = $a
    $email = $e
  end function

end structure
  

Instead of the full word structure being used, the keyword struct may be used.

A structure must be declared using the new or copyof keywords.

Variables and internal functions can be accessed using the object pointer literal, -> as shown below:

YASS
function main($args)
  $s = new person()
  $t = copyof person()

  //Run an internal function within a structure
  $t->set("Jack", 20, "[email protected]")
  //Obtain and print a variable from a structure
  print($t->$name)
  //Set a variable in a structure
  $t->$name = "Joseph"
end function
  

Prior to version 1.5.3, the object pointer literal was called the pointer literal and was represented by => (fat arrow).

Structures may also be constructed with parameters as of version 1.5.2 of ZPE. The important thing is that they have a function named _construct:

YASS
structure person

  $name = null
  $age = 0
  $email = null

  function _construct($n, $a, $e)
    $name = $n
    $age = $a
    $email = $e
  end function

end structure

function main($args)
  $p = new person("John", 20, "[email protected]")
end function
  

YASS
structure Person

  $name = null
  $age = 0
  $email = null

  function _output()
    return $name & " " & $age
  end function

end structure

  

Remember, in ZPE, structures are templates or prototypes for new objects and objects are the instantiated versions of these structures.

There are other special functions that can be used within an object such as the _output or the _compare functions:

YASS
structure Person

  $name = null
  $age = 0
  $email = null

  function _construct($n, $a, $e)
    $name = $n
    $age = $a
    $email = $e
  end function

  function _output()
      return this->$name & "(" & this->$email & ")"
  end function

  function _compare($o)
    return $o->$name == this->$name
  end function

end structure
function main($args)
  $p1 = new Person("John", 20, "[email protected]")
  $p2 = new Person("John", 48, "[email protected]")

  //Will return true
  print($p1 == $p2)
end function
  

Version 1.6.4 of ZPE added ZPEObjectNativeFunctions as an option which allows functions defined within Java to add native Java-based function calls on objects.

Comments

There are no comments on this page.

New comment
Reply
Provide feedback on this page
Comments are sent via email to me.