Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Official ZPE/YASS documentationObject data type

Structures inherit the features of objects. Structures are basically prototypes or templates of object in that they pre-define functions and variables within themselves. This allows the application to define it's own loosely attached variables. Objects like this can be powerful containers for multiple variables. Just as before, the object pointer (->) symbol allows access to the object's internal properties.

Objects are defined using the { } notation as of version 1.6.3:

$obj = {}

Prior to 1.6.3, objects needed to be defined using the new object() syntax.

$x = {}
$x->$y = 10

In YASS, objects can be seen as structures without rules. It is important to note that if you are chaining these, you must define each inner variable as an object like so:

$x = {}
$x->$y = {}
$x->$y->$a = 10
$x->$y->$b = 15

These inner values can also be assigned with functions, taking advantage of lambda functions makes this easy:

$x = {}
$x->$y = function() print (true) end function

It is important to note that functions cannot be directly assigned to objects but must first be abstracted using lambda functions as above.

Objects became available in version 1.4.1 and cannot be used in versions prior to this.

As of version 1.5.2 it is also possible to serialize and deserialize objects and structures using ZPE's object serialise (save) and deserialise (open) functions:

ZPE 1.6.6 changed the way that serialisation works on objects so both syntaxes are shown below:

$x = {}
$x->$y = function() print(true) end function
//ZPE 1.5.2+
//ZPE 1.6.6+
$y = deserialise("test.output")

ZPE 1.6.3 completely redesigned the way objects work underneath the compiler and interpreter to make it possible to perform other operations on objects. For example:

structure person
  $name = ["Jamie", "Balfour"]
  $age = 27
  $email = "test@jamiebalfour.scot"
end structure
function main($args)
  $p = new person()
  $first = $p->$name[0]
  $second = $p->$name[1]
end function

It should be noted that version 1.5.4 added an alternative syntax for defining un-prototyped objects using the JSON notation:

$person = {forename : "Jamie", surname : "Balfour"}

This was a big update that inlines ZPE with ECMAScript's definition of objects.

Version 1.6.5 also changed the way that the serialisation and object definitions of objects was performed by adding 'native functions' to the object:

$person = {forename : "Jamie", surname : "Balfour"}

Version 1.7.4 further improves objects by adding inline access to internal objects and is by far the simplest method of using these internally defined classes. For example, ZPE defines a UIBuilder object internally:

$ui = new UIBuilder()

It is also very important to note that all objects and structures use by reference variable assignment. This means that changing an object variable inside one function affects another.

$v = {name : "Test object", inner : {name : "Test inner object"}}
$x = $v->inner
$x->name = "Test inner object new"

In most cases this is desirable, however an easy way to get around this is to perform a copy on the object.

Feedback 👍
Comments are sent via email to me.